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

Tip: Looking for answers? Try searching our database.

Adding text to specifc section of a footer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Rowland - 29 Mar 2005 23:26 GMT
Hi this is my first post to this forum and hope someone can help!!
(Will be using this on Word97)

What I am trying to do is as follows:

Upon Print/Print Preview I wish the network User ID into my document
footer. (This I have managed)
More specfically I wish to add to exsisting footer text. I have a 3x3
table and wish to add this data into cell C3 (ie bottom right) (This I
can't manage) and I would be gratful if anyone can assit.

Below is the code I have managed to pull together (Just the
PrintPreview bit to save space).

Sub FilePrintPreview()
'
' FilePrintPreview Macro
' Displays full pages as they will be printed
'
   ActiveDocument.PrintPreview
   
   strUser = LCase(Environ("username"))

' Open Header/Footer view

 If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
       ActiveWindow.Panes(2).Close
   End If
   If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
       ActivePane.View.Type = wdOutlineView Then
       ActiveWindow.ActivePane.View.Type = wdPrintView
   End If
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   If Selection.HeaderFooter.IsHeader = True Then
       ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
   Else
       ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
   End If

' Add Footer Text
Selection.MoveRight Unit:=wdCell
   Selection.MoveRight Unit:=wdCell
   Selection.MoveRight Unit:=wdCell
   Selection

Many thanks
Jon
Jay Freedman - 30 Mar 2005 03:18 GMT
Hi Jon,

In Word, working with the Selection (which simultaneously moves the
insertion point in the document) is the worst possible choice,
especially when working in headers and footers. The fact that this
garbage is what the macro recorder supplies is nothing short of
criminal.

Use the power of the Word object model to make life simpler! This is
all the code you need:

Sub FilePrintPreview()
   Dim oRg As Range
   Dim strUser As String
   
   strUser = LCase(Environ("username"))
   
   Set oRg = ActiveDocument.Sections(1) _
       .Footers(wdHeaderFooterPrimary) _
       .Range.Tables(1).Cell(1, 3).Range
       
   oRg.Text = strUser
   
   ActiveDocument.PrintPreview
End Sub

The Set statement works like this: Choose the first (probably the
only) section in the active document. Choose the primary footer of
that section (as opposed to the first-page footer or the even-page
footer, if they exist). Within the range of that footer, choose the
first (presumably the only) table. Within that table, choose the cell
in row 1 / column 3. Assign the range of that cell to the Range
variable oRg.

Then it remains only to assign the strUser variable to the .Text
property of the chosen Range.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Hi this is my first post to this forum and hope someone can help!!
>(Will be using this on Word97)
[quoted text clipped - 46 lines]
>Many thanks
>Jon
news.btinternet.com - 30 Mar 2005 13:09 GMT
Thanks Jay,

Tried this but bit

      Set oRg = ActiveDocument.Sections(1) _
      .Footers(wdHeaderFooterPrimary) _
      .Range.Tables(1).Cell(1, 3).Range

causes a compile error=syntax error, I think it is down to the _ but don't
know how why it causes the error, so can't fix it

Thanks

Jon

> Hi Jon,
>
[quoted text clipped - 88 lines]
> >Many thanks
> >Jon
news.btinternet.com - 30 Mar 2005 16:09 GMT
my error...forgot to add the space...doh!!!...Thanks v much works a treat.

Jon

> Hi Jon,
>
[quoted text clipped - 88 lines]
> >Many thanks
> >Jon
 
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.