Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default How to get Word Header Text into Excel VBA

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(wdHeaderFooterP rimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).R ange.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!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default How to get Word Header Text into Excel VBA

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

MikeZz wrote:
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(wdHeaderFooterP rimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).R ange.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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default How to get Word Header Text into Excel VBA

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

" wrote:

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

MikeZz wrote:
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(wdHeaderFooterP rimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).R ange.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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default How to get Word Header Text into Excel VBA

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

test = oWord.Selection.Information(3)

" wrote:

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

MikeZz wrote:
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(wdHeaderFooterP rimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).R ange.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!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default How to get Word Header Text into Excel VBA

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

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

test = oWord.Selection.Information(3)

" wrote:

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

MikeZz wrote:
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(wdHeaderFooterP rimary).Range.Text

Failed Excel VBA Command
test = oWord.Sections(1).Headers(wdHeaderFooterPrimary).R ange.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!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move logo from word document to excel header Blue Bunny Excel Discussion (Misc queries) 3 August 22nd 08 04:08 PM
I want to use a standard 'Word' field in my Excel header Gail Excel Discussion (Misc queries) 0 November 11th 07 01:18 AM
Same header and footer in excel and word Bugsy Excel Worksheet Functions 0 May 23rd 07 02:22 PM
Tranferring Text from Excel to a Header in Word Mike Excel Programming 0 June 23rd 05 04:30 PM
Coyping from Excel to an MS Word Header Mike Excel Programming 0 January 22nd 04 01:41 PM


All times are GMT +1. The time now is 03:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"