首页 > 解决方案 > 阅读表单时未更新内容链接的自定义文档属性

问题描述

为了映射标题块元数据,我添加了具有相同名称的范围名称和自定义文档属性。Rangenames 和 cust doc prop 链接到内容。我创建了一个读取 cust doc 属性的表单,以便用户可以在需要时进行调整。关闭表单时,它将新值保存到范围名称中,因此保存到 cust doc 道具中,并且表单被关闭。当再次显示表单时,它仍然从 cust doc prop 中读取旧值。在 file/prop 下显示修改后的值。

对我来说似乎是一个错误。

在显示表单之前阅读 cust doc 道具

For Each p In ActiveWorkbook.CustomDocumentProperties
On Error GoTo Errorhandler
'Match the property with the position in the array, i=0 if not found
i = IndexTCProp(p.Name)
If p.Name = "TC_Project_Name" Then Debug.Print ActiveWorkbook.Name, i,  'p.Name, p.Value
 'fill the form with the found TC Prop and it's value.
  If i > 0 Then
    ipos = ipos + 1
    frm_DocProp.Controls.Item("label_" & ipos).Caption = ActiveWorkbook.CustomDocumentProperties.Item(aTC_Prop(ipos, 1)).Name
    frm_DocProp.Controls.Item("text_" & ipos).Value = ActiveWorkbook.CustomDocumentProperties.Item(aTC_Prop(ipos, 1)).Value
    frm_DocProp.Controls.Item("text_" & ipos).Enabled = True  'Default editable
  End If
Next

在表单中,更改的值被写入单元格和链接的 cust doc prop。

Private Sub cb_OK_Click()
Dim x As Integer
Dim p As DocumentProperty
' Write changes into cust doc prop
For x = LBound(aTC_Prop) To UBound(aTC_Prop)
   On Error Resume Next
   Range(aTC_Prop(x, 1)) = frm_DocProp.Controls.Item("text_" & x).Value
Next
Unload Me
End Sub

加载表单并再次读取更改后的 cust doc prop 仍会显示旧值。文件/属性/自定义下显示的值显示更改后的值。这是一个错误还是我需要刷新一些东西?

标签: excelvba

解决方案


推荐阅读