我正在尝试使代码通过包含重复部分内容控件(RepSecCC)的word文档运行,其中包含几个嵌套的CC。我想编写宏,它会为每个 RepSecCC 生成新的 Word 文档(从模板)并用来自嵌套 CC 的信息填充它。
我当前的代码仅生成一个文档并使用上一个 RepSecCC 的信息填充它的问题。我不明白为什么它会跳过所有其他 RepSecCC。我应该在哪里调整我的代码?
Dim objWord As Object
Dim objDoc As Object
Dim pack As String, Reg_No As String, VP_name As String,
Dim CC As Word.ContentControl
Dim rCC As Word.ContentControl
Set objWord = CreateObject("Word.Application")
MsgBox "Document's are generated. Please wait"
For Each rCC In ActiveDocument.ContentControls
If rCC.Title = "New_section" Then
For Each CC In rCC.Range.ContentControls
If CC.Tag = "LI_NO" Then
Reg_No = CC.Range.Text
ElseIf CC.Tag = "VP_pav" Then
VP_name = CC.Range.Text
ElseIf CC.Tag = "Pack" Then
pack = CC.Range.Text
pack = UCase(Left(pack, 1)) & Mid(pack, 2)
End If
Next CC
Set objDoc = objWord.Documents.Add(Template:="S:\bendri\VRS\VRS Administravimas\6 Lygiagretus importas\LI registracijos sarasas\LI_sablonasM.dotm", NewTemplate:=False, DocumentType:=0)
objWord.Visible = True
With objDoc
.ContentControls.Item(1).Range.Text = Reg_No
.ContentControls.Item(2).Range.Text = VP_name
.ContentControls.Item(4).Range.Text = pack
End With
End If
Next rCC
MsgBox "Finished. Please continue"
End Sub