[英]copy word doc footer to excel using vba
Trying to get the footer text in a MS_Word Doc with an excel macro and paste it into an excel sheet. 尝试使用Excel宏在MS_Word文档中获取页脚文本,然后将其粘贴到Excel工作表中。 this VBA code works in MS_WORD but NOT in MS_EXCEL macro. 此VBA代码适用于MS_WORD,但不适用于MS_EXCEL宏。 I checked and the section count = 1 in the document. 我检查并在文档中节数= 1。
Dim wdDoc As Object
Dim h As Object 'Word.HeaderFooter
Dim docver As String 'Paste this to excel
Set wdDoc = GetObject("D:docname.docx")
With wdDoc
For Each h In .Sections
docver = h.Footers(wdHeaderFooterPrimary).Range.Text
Next
End With
I was able to use the "watch window" under the VBA project view to determine the Syntax structure. 我可以使用VBA项目视图下的“监视窗口”来确定语法结构。 the correct syntax is as follows: 正确的语法如下:
For Each h In .Sections.Item.Footers 对于.Sections.Item.Footers中的每个h
docver = h.Footers.Item(1).Range.Text
Next 下一个
how to I extract a footer for each document. It is only finding the footer for the first document.
Currently my code is
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Dim docvers As String
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("U:\word" & "\")
i = 1
strDirectory = "U:\word" & "\"
varDirectory = Dir(strDirectory, vbNormal)
docvers = strDirectory & varDirectory
Dim wdDoc As Object
Dim h As Object 'Word.HeaderFooter
Dim docver As String 'Paste this to excel
Set wdDoc = GetObject(docvers)
With wdDoc
For Each h In .Sections
docver = h.footers.Item(2).Range.Text
Next
End With
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path
Cells(i + 1, 2) = objFile.Path
Cells(i + 1, 3) = docver
i = i + 1
Next objFile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.