我想在Word中复制一个excel表格到一个特定的章节。我需要在页眉中搜索一个字符串,如果页眉中包含该字符串,那么脚本就必须把一个表格放到该节中(在该节的第一页)。我试过这样做,但它不工作。错误说。The requested element ist not in the collection. 当我试着打印它时,他给我显示了正确的标题,所以我认为问题是在if-loop...
Dim Headers_text As String
Dim CountSections As Integer
Dim intSections As Integer
CountSections = wDoc.Sections.Count
For intSections = 1 To CountSections
Headers_text = wDoc.Sections(intSections).Headers(1).Range.Text
If InStr(Headers_text, "Part 1") Then
Sheet_test.UsedRange.CopyPicture Appearance:=xlScreen, Format:=xlPicture
wDoc.Sections(intSections).Range.Paste
End If
Next
希望有人能帮助我
谢谢
试试吧。
Dim s As Long
With wDoc
For s = 1 To .Sections.Count
With .Sections(s)
If InStr(.Headers(1).Range.Text, "Part 1") > 0 Then
Sheet_test.UsedRange.CopyPicture Appearance:=xlScreen, Format:=xlPicture
.Range.Characters.First.Paste
End If
End With
Next
End With