--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
"JH Palmer" <JHPa...@discussions.microsoft.com> wrote in message
news:3E4AAA86-78C5-4F22...@microsoft.com...
> I am well versed in Excel VBA but I'm finding Word more difficult.
>
> I would like to write a macro to enter the date left aligned, page x of y
> centered and the pathname rightaligned all in one row of the page footer.
>
> In Excel it's understandable
>
> ActiveSheet.PageSetup.LeftFooter = "&8&H&X&D &T"
>
> ActiveSheet.PageSetup.RightHeader = "&8&H&XPage &P of &N"
>
> Could someone kindly advise the code to use for word?
>
> Thanks in advance for your assistance.
>
> JH Palmer
>
>
This might get you started. Hacked together from code
Doug Robbins posted for FLUSH right. It only affects the
primary footer, so if you run the code and then change
Page Layout Header and Footer sections you will need to
copy the text to the ODD, Even, or First Page footer. I
suppose you could make that automatic with a little more
code:
Sub SetupFooter()
On Error GoTo ErrorHandling
Dim sngLeftMargin As Single
Dim sngRightMargin As Single
Dim sngPageWidth As Single
Dim sngWidthToRight As Single
Dim sngHalfWayPoint As Single
'Retrieve margin, center and page width values
sngLeftMargin = CSng(ActiveDocument.PageSetup.LeftMargin)
sngRightMargin = CSng(ActiveDocument.PageSetup.RightMargin)
sngPageWidth = CSng(ActiveDocument.PageSetup.PageWidth)
sngWidthToRight = sngPageWidth - (sngLeftMargin +
sngRightMargin)
sngHalfWayPoint = sngWidthToRight / 2
Application.ScreenUpdating = False
'Go to footer
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
'Position Tabs Stops
With Selection.Paragraphs.TabStops
.ClearAll
.Add Position:=sngHalfWayPoint,
Alignment:=wdAlignTabCenter, Leader:=wdTabLeaderSpaces
.Add Position:=sngWidthToRight,
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
End With
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="CREATEDATE"
Selection.MoveRight Unit:=wdCharacter, Count:=3,
Extend:=wdMove
Selection.TypeText Text:=vbTab
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="PAGE"
Selection.MoveRight Unit:=wdCharacter, Count:=3,
Extend:=wdMove
Selection.TypeText Text:=" of "
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="NUMPAGES"
Selection.MoveRight Unit:=wdCharacter, Count:=3,
Extend:=wdMove
Selection.TypeText Text:=vbTab
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="FILENAME \p"
Selection.WholeStory
Application.Run
MacroName:="Normal.MyMacros.UpdateFields"
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
Application.ScreenUpdating = True 'display on
ErrorHandling:
End Sub
>-----Original Message-----
>I am well versed in Excel VBA but I'm finding Word more
difficult.
>
>I would like to write a macro to enter the date left
aligned, page x of y
>centered and the pathname rightaligned all in one row of
the page footer.
>
>In Excel it's understandable
>
> ActiveSheet.PageSetup.LeftFooter = "&8&H&X&D &T"
>
> ActiveSheet.PageSetup.RightHeader = "&8&H&XPage &P
of &N"
>
>Could someone kindly advise the code to use for word?
>
>Thanks in advance for your assistance.
>
>JH Palmer
>
>
>.
>
Saying it's more complicated than Excel was an understatement.
Is this missing an "updateFields" macro?
I had to remove several carriage returns to get rid of compile errors but I
still couldn't get it to run.
Yes it is missing an an update fields. I has my Update Fields macro, but
then you don't do you :-)
Sorry.
Try changing: Application.Run MacroName:="Normal.MyMacros.UpdateFields"
to ActiveDocument.Fields.Update
I cobbled this thing together during a slow moment at work. I just copied
here at home and seem to work just fine.
You know, I don't know what you are really trying to do, but it seem like
you could just create a template with this informtion and format your
documents that way.
--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in gma...@whamspammvps.org
That did the trick.
You're right, I should set up a template, and I will have to do that.
You're program is very useful for cases when someone else sends me a
document. Very often we have to update something and can't remember it is
saved under "H:\procedures\accounting\month end\..."
I think all documents should have the whole pathname in the footer.
One more thing. Could you tell me the code to make it a smaller font?
Have a good day.
Jim Palmer
Try this:
'Go to footer
'Position Tabs Stops
With Selection
.Font.Size = 6
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="CREATEDATE"
.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdMove
.TypeText Text:=vbTab
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="PAGE"
.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdMove
.TypeText Text:=" of "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="NUMPAGES"
.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdMove
.TypeText Text:=vbTab
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="FILENAME \p"
.WholeStory
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True 'display on
ErrorHandling:
End Sub
Jim
Its much better to have a macro to run on existing files or when you
want rather than a template. Template's are only good when you are
creating from scratch - and frankly not so good then.
OK - good luck
AfricanHealer
JH Palmer wrote:
> *I am well versed in Excel VBA but I'm finding Word more difficult.
>
> I would like to write a macro to enter the date left aligned, page x
> of y
> centered and the pathname rightaligned all in one row of the page
> footer.
>
> In Excel it's understandable
>
> ActiveSheet.PageSetup.LeftFooter = "&8&H&X&D &T"
>
> ActiveSheet.PageSetup.RightHeader = "&8&H&XPage &P of &N"
>
> Could someone kindly advise the code to use for word?
>
> Thanks in advance for your assistance.
>
> JH Palmer *
--
AfricanHealer
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message960974.html