更新Word表单字段

时间:2015-05-20 17:42:17

标签: vba ms-word word-vba

我有一个我正在处理的Word表单。

它有一个应该从其他字段计算的字段。

在上一次迭代中,您可以单击表格中的单元格并按F9,该字段将更新。

我已经添加了一些其他按钮和VBA,现在当“限制编辑”打开时,您无法再单击该单元格。

我尝试了一个绑定到VBA的按钮,它将更新所有字段,但是当您单击该按钮时,您无法编辑任何字段。

如何更新此字段,仍然可以手动更新其他字段?

1 个答案:

答案 0 :(得分:0)

问题在于内容控件和ActiveX按钮并不完全兼容。此外,我继承了表单的程序员使用的是基于文档中的表而不是VBA的简单字段计算。我能够提出更好的解决方案。我使用了子:

Private Sub Document_ContentControlOnExit(ByVal thisControl As ContentControl, Cancel As Boolean)    
End Sub

从控件执行代码onExit。当用户退出内容控件时,此函数在所有内容控件上执行。我开发的另一个工具是以下函数,它将找到具有给定标题的控件的索引:

'Function to get control index given the control title
'PARAMETER Control Title as String
'RETURN Control Index as Integer
Public Function GetControlIndex(ccTitle As String) As Integer
    'Function Variable Declaration
    Dim objCC As ContentControl

    'look at each ContentControl
    For i = 1 To ActiveDocument.ContentControls.count
        Set objCC = ActiveDocument.ContentControls.Item(i)
        With objCC
            If .Title = ccTitle Then
                GetControlIndex = i
            End If
        End With
    Next i
End Function
相关问题