Reputation: 31
Trying to get the footer text in a MS_Word Doc with an excel macro and paste it into an excel sheet. this VBA code works in MS_WORD but NOT in MS_EXCEL macro. I checked and the section count = 1 in the document.
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
Upvotes: 1
Views: 1460
Reputation: 1
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
Upvotes: -1
Reputation: 31
I was able to use the "watch window" under the VBA project view to determine the Syntax structure. the correct syntax is as follows:
For Each h In .Sections.Item.Footers
docver = h.Footers.Item(1).Range.Text
Next
Upvotes: 2