Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Before Save 1

Status
Not open for further replies.

simoncpage

Programmer
Apr 4, 2002
256
GB
Hi all, an interesting one that I'm not sure how to work out.

A new word document is created it is then saved is there any way of adding in the filename and directory after saving the file i.e it automatically saves it again with these details in the header?

Any idea would be most appreciated???

Thanks

Simon
 
Hi Simon
If I understand you correctly the following will add filename & path into the header of the active document (I hope)

Code:
Sub standard()
'
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
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    &quot;FILENAME \p &quot;, PreserveFormatting:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

However, if you substitute these lines it won't work. Dunno why

Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
[b]NormalTemplate.AutoTextEntries(&quot;Filename and path&quot;).Insert Where:= _
        Selection.Range[/b]
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
;-) If a man says something and there are no women there to hear him, is he still wrong?
 
I've actually got that far the problem I have is that unlike excel there isnt a beforesave / beforeprint procedure. I want to add in the filename to the header when the person saves the file or prints the file wwithout having to click on another macro button before hand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top