By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Filling out headers with date in Word

Expert 100+
P: 844
I'm trying to use visual basic to automatically write headers. Something like this:
Expand|Select|Wrap|Line Numbers
  1. <my name>                       <class>
  2. <date>                      <my <class>'s teacher's name>
I went to record macro and I did the header manually and I got this code:
Expand|Select|Wrap|Line Numbers
  1. Sub EnglishHeader()
  2.     If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
  3.         ActiveWindow.Panes(2).Close
  4.     End If
  5.     If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
  6.         ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _
  7.          = wdMasterView Then
  8.         ActiveWindow.ActivePane.View.Type = wdPageView
  9.     End If
  10.     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
  11.     Selection.TypeText Text:="<my name>" & vbTab & vbTab & "English"
  12.     Selection.TypeParagraph
  13.     Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate
  14.     Selection.TypeText Text:=vbTab & vbTab & "<my teacher's name>"
  15.     ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
  16. End Sub
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.
Sep 30 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.