How to get Word Header Text into Excel VBA

G

Guest

I have a macro that pulls information from a word file but can't get to the
Header string.

In word2003, I can get the following vba command to pull the text from the
header. The question is how to run this command from within Excel.

Working Word VBA Command
test = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text

Excel VBA Error:
"Compile Error. Methood or data member not found."

For reference, I've used the following other commands to run Word from Excel:
Dim oWord As Word.Application
Set oWord = GetObject(, "Word.Application")
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
.Text = "Product/DRD FAM"
.Wrap = wdFindContinue
End With
oWord.Selection.Find.Execute 'Finds Start of EWO Body
oWord.Selection.MoveRight Unit:=wdCell

Thanks!
 
A

aidan.heritage

You are using Word constants, without (I suspect) having bound to the
word object - instead of wdHeaderFooterPrimary use the digit 1 - so

test = ActiveDocument.Sections(1).Headers(1).Range.Text

should be fine - 1 is the value of that particular word constant
 
G

Guest

Any idea what the magic command is to get the Current Page # and total pages
of the Word file (while in Excel VBA)
 
G

Guest

For Inquiring Minds who want to know how to get the current Page Number:

test = oWord.Selection.Information(3)
 
A

aidan.heritage

and oword.selection.information(4) would give you the total number of
pages in the document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top