请有人以编程方式帮助 MS Word 的 ContentControl 格式化。我编写了一个代码,根据其标签转到特定的 ContentControl。通过转到由其标签指定的每个 ContentControl,此代码运行良好。但是我只需要在第 2 页上格式化 ContentControls。
我试图仅针对特定的书签、页面、表格限制循环,但它不起作用。我不需要遍历文档中的每个ContentContorl,它需要太多时间,这与宏的目的相反。我正在创建这个宏来加快报告格式。
这是我的代码:
Sub EditCCbyTag()
Dim cc As ContentControl
Dim strText As String
Dim oThisdoc As Word.Document
Dim oCC1 As ContentControl
Dim oCCs1 As ContentControls
Dim oCC2 As ContentControl
Dim oCCs2 As ContentControls
Dim oCC3 As ContentControl
Dim oCCs3 As ContentControls
Set oThisdoc = ActiveDocument
Set oCCs1 = oThisdoc.SelectContentControlsByTag("DgDocDate01")
For Each oCC1 In oCCs1
If oCCs1.Count > 0 Then
oCC1.Range.Select
Dialogs(wdDialogContentControlProperties).Show
strText = InputBox("Please enter the DATE of report")
Set cc = ActiveDocument.SelectContentControlsByTag("DgDocDate01")(1)
cc.Range.Text = strText
End If
Next oCC1
' the next CC DgDnvReportNo01
Set oThisdoc = ActiveDocument
Set oCCs2 = oThisdoc.SelectContentControlsByTag("DgDnvReportNo01")
For Each oCC2 In oCCs2
If oCCs2.Count > 0 Then
oCC2.Range.Select
Dialogs(wdDialogContentControlProperties).Show
strText = InputBox("Please enter the NUMBER of report")
Set cc = ActiveDocument.SelectContentControlsByTag("DgDnvReportNo01")(1)
cc.Range.Text = strText
End If
Next oCC2
' the next CC DgRevNo01
Set oThisdoc = ActiveDocument
Set oCCs3 = oThisdoc.SelectContentControlsByTag("DgRevNo01")
For Each oCC3 In oCCs3
If oCCs3.Count > 0 Then
oCC3.Range.Select
Dialogs(wdDialogContentControlProperties).Show
strText = InputBox("Please enter the REVISION of report")
Set cc = ActiveDocument.SelectContentControlsByTag("DgRevNo01")(1)
cc.Range.Text = strText
End If
Next oCC3
MsgBox "Done!"
End Sub