Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Headers, footers and macros

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jorge - 12 Oct 2005 13:13 GMT
Hi

Do you know how can I place the insertion point in a header/footer from my
macro?

Best

Jorge
Helmut Weber - 12 Oct 2005 17:50 GMT
Hi Jorge,

you don't need an insertion point at all.

This one will replace the 4th character
in an ordinary footer with "vvv".

Dim r As Range
Set r = ActiveDocument.StoryRanges(wdPrimaryFooterStory)
With r
  .Characters(4).Text = "vvv"
End With

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Jorge - 13 Oct 2005 08:31 GMT
Well, I think I do need the insertion point in the header because I want to
do a search inside the header. At the moment I'm using these two instructions
at the beginning and the end of my procedure:

   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   ...
   ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

> Hi Jorge,
>
[quoted text clipped - 8 lines]
>    .Characters(4).Text = "vvv"
> End With
Helmut Weber - 13 Oct 2005 10:52 GMT
No.

Have a look at this:

Dim r As Range
Set r = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
With r.Find
.Text = "dk"
.Replacement.Text = "xx"
' clear other options in addition
.Execute Replace:=wdReplaceAll
End With

Greetings from Bavaria

Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Debra Ann - 11 Oct 2006 14:29 GMT
I need to replace text that is in the footers throughout a document and I
came across this helpful suggestion.  However, when I try to run the code it
doesn't do anything.  Have I done something wrong?  Here is my code:

Dim r As Range

Set r = ActiveDocument.StoryRanges(wdPrimaryFooterStory)

With r.Find
   .Text = "NP Inc."
   .Replacement.Text = "NP Canada Ltd."
   .Execute Replace:=wdReplaceAll
End With

Signature

Debra Ann

> No.
>
[quoted text clipped - 14 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
Debra Ann - 11 Oct 2006 14:27 GMT
I needed to replace all instances of "NP Inc" in all footers throughout a
document and came across this helpful note.  However, when I try to run it,
it doesn't do anything.  Below is my code.  Have I done something wrong?

Dim r As Range

Set r = ActiveDocument.StoryRanges(wdPrimaryFooterStory)

With r.Find
   .Text = "NP Inc."
   .Replacement.Text = "NP Canada Ltd."
   .Execute Replace:=wdReplaceAll
End With

Signature

Debra Ann

> Hi
>
[quoted text clipped - 4 lines]
>
> Jorge
Greg Maxey - 11 Oct 2006 14:54 GMT
Works here if the footer is a primaryfooter

To process each footer storytype, try:

Sub ScratchMacro()
Dim i As Long
Dim rngStory As Word.Range
i = ActiveDocument.Sections(1).Headers(1).Range.StoryType
'Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
 Do
   Select Case rngStory.StoryType
     Case 8, 9, 11 'Corresponds to First, Primary and Even page footer
story
       With rngStory.Find
         .Text = "NP Inc."
         .Replacement.Text = "NP Canada Ltd."
         .Execute Replace:=wdReplaceAll
       End With
     Case Else
       'Do Nothing
     End Select
   Set rngStory = rngStory.NextStoryRange
 Loop Until rngStory Is Nothing
Next
End Sub

> I needed to replace all instances of "NP Inc" in all footers throughout a
> document and came across this helpful note.  However, when I try to run it,
[quoted text clipped - 21 lines]
> >
> > Jorge
Debra Ann - 25 Oct 2006 16:38 GMT
Greg,

This worked beautifully.  I'm sorry I am just getting back to you on this
"wonderful" code.   I somehow missed the notification that the quesiton was
answered and got involved in something else the last couple of weeks.  

But ... thank you, thank you, thank you  ;-)

Signature

Debra Ann

> Works here if the footer is a primaryfooter
>
[quoted text clipped - 48 lines]
> > >
> > > Jorge
Debra Ann - 25 Oct 2006 16:57 GMT
Oops, just realized one thing it didn't change.  

On my Table of Contents, List of Tables, and List of Figures sections, I
have a first page of section footer and the rest of the section footer.  
Until the engineers add information into the template, each one of these
sections only contain one page each.  Therefore, the section footers for the
rest of the section that are hidden because they have not been used yet, do
not change with this code.  It is only obvious once the Table of Contents
goes to two pages and the footer still contains the wrong company.  Is there
any way to fix this?

Signature

Debra Ann

> Works here if the footer is a primaryfooter
>
[quoted text clipped - 48 lines]
> > >
> > > Jorge
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.