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 / September 2005

Tip: Looking for answers? Try searching our database.

How do I prevent macro from replacing entire footer?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Myoshia - 12 Aug 2005 18:54 GMT
I currently have a macro that pulls in external information into the
footer(s) of my document and thus far, the information comes over just fine.  
However, I am not familiar enough with VBA to:

1.  make sure that the info appears in EVERY footer (whether the section is
set to Different First Page or not)
2.  make sure that if there is existing text in my footer (most commonly a
page number), that it doesn't get wiped out (I'm assuming by the .range).  

Again, I'm not familiar enough with VBA to tell it to only remove that which
is beyond the first line (which is quite often where the page number
appears).  Here's the code I am currently using:

   Dim objRange As Word.Range
   Dim objFont As Word.Font
   
   Set objRange =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
   Set objFont = objRange.Font
   
   objRange.Style = wdStyleFooter
   objRange.Text = strTextString
   
   With objFont
       .Size = 8
   End With
   
   If ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Exists =
True Then
       
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Text _
               = strTextString
   End If
   
   Set objRange = Nothing
   Set objFont = Nothing
End Sub

I hope this is not confusing.  Please advise and thanks in advance.
Doug Robbins - 12 Aug 2005 21:11 GMT
I would have placed a { Docvariable "varname" } field into each of the
footers and the used code to set the value of the document variable and
then, the quick and dirty way to update the display of the information is to
use

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

The alternative code to do the updating is

Dim i As Long
With ActiveDocument
   For i = 1 To .Sections.Count
       .Sections(i).Footers(wdHeaderFooterFirstPage).Range.Fields.Update
       .Sections(i).Footers(wdHeaderFooterPrimary).Range.Fields.Update
   Next i
End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I currently have a macro that pulls in external information into the
> footer(s) of my document and thus far, the information comes over just
[quoted text clipped - 38 lines]
>
> I hope this is not confusing.  Please advise and thanks in advance.
Myoshia - 12 Sep 2005 18:45 GMT
I was able to piece together a litlle from each response and it worked like a
charm.  I thank each of you (Doug and Greg) for all of your help.  This
newsgroup is so very helpful.

> I would have placed a { Docvariable "varname" } field into each of the
> footers and the used code to set the value of the document variable and
[quoted text clipped - 56 lines]
> >
> > I hope this is not confusing.  Please advise and thanks in advance.
Greg - 12 Aug 2005 21:18 GMT
You might need to refine this a bit but it might suit your needs.

Sub Test1()
Dim myRng As Range
For Each myRng In ActiveDocument.StoryRanges
 If myRng.StoryType = 8 Or myRng.StoryType = 9 Or myRng.StoryType = 11
Then
   myRng.Collapse Direction:=wdCollapseEnd
   myRng.InsertAfter vbCr & "Your text here"
   While Not (myRng.NextStoryRange Is Nothing)
     Set myRng = myRng.NextStoryRange
     myRng.Collapse Direction:=wdCollapseEnd
     myRng.InsertAfter vbCr & "Your text here"
   Wend
 End If
Next
End Sub
Greg Maxey - 13 Aug 2005 02:28 GMT
Or this version:

Sub InsertTextAfterCurrentTextInFooters()
Dim myRng As Range
For Each myRng In ActiveDocument.StoryRanges
 Select Case myRng.StoryType
   Case Is = 8, 9, 11
     Do
       myRng.Collapse Direction:=wdCollapseEnd
       myRng.InsertAfter vbCr & "Your text here"
       Set myRng = myRng.NextStoryRange
     Loop Until myRng Is Nothing
   Case Else
     'Do nothing
 End Select
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I currently have a macro that pulls in external information into the
> footer(s) of my document and thus far, the information comes over
[quoted text clipped - 37 lines]
>
> I hope this is not confusing.  Please advise and thanks in advance.
 
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.