Filling out headers with date in Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    Filling out headers with date in Word

    Hello,
    I'm trying to use visual basic to automatically write headers. Something like this:
    Code:
    <my name>                       <class>
    <date>                      <my <class>'s teacher's name>
    I went to record macro and I did the header manually and I got this code:
    [code=vb]
    Sub EnglishHeader()
    If ActiveWindow.Vi ew.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Pa nes(2).Close
    End If
    If ActiveWindow.Ac tivePane.View.T ype = wdNormalView Or ActiveWindow. _
    ActivePane.View .Type = wdOutlineView Or ActiveWindow.Ac tivePane.View.T ype _
    = wdMasterView Then
    ActiveWindow.Ac tivePane.View.T ype = wdPageView
    End If
    ActiveWindow.Ac tivePane.View.S eekView = wdSeekCurrentPa geHeader
    Selection.TypeT ext Text:="<my name>" & vbTab & vbTab & "English"
    Selection.TypeP aragraph
    Selection.Field s.Add Range:=Selectio n.Range, Type:=wdFieldDa te
    Selection.TypeT ext Text:=vbTab & vbTab & "<my teacher's name>"
    ActiveWindow.Ac tivePane.View.S eekView = wdSeekMainDocum ent
    End Sub
    [/code]
    I copied and pasted that for all of my classes so instead of writing the header manually the macros do it for me. However, I need the date to be the date when I wrote the document not the date when I'm looking at it. Because, when I open the document a couple of days later the date isn't preserved and it shows the current date. Is there any way I can make the date stay like it was the day when I wrote the document? Even if I change the date manualy, the next time I open the file, it changes back to the current date. So that means that the macro is run everytime I open the document? I'm sorry if this is really simple but I haven't used vb at all. Appreciate any help.
Working...