+ Reply to Thread
Results 1 to 5 of 5

How to get Word Header Text into Excel VBA

  1. #1
    MikeZz
    Guest

    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(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!


  2. #2
    aidan.heritage@virgin.net
    Guest

    Re: 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(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!



  3. #3
    MikeZz
    Guest

    Re: 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)

    "aidan.heritage@virgin.net" 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(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!

    >
    >


  4. #4
    MikeZz
    Guest

    Re: 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)

    "aidan.heritage@virgin.net" 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(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!

    >
    >


  5. #5
    aidan.heritage@virgin.net
    Guest

    Re: 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)
    >
    > "aidan.heritage@virgin.net" 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(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!

    > >
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1