I'm an Access VBA girl, and having trouble with some Word VBA. I never do any programming in MS Word, so I'm struggling. In my Access db, the user hits a button which exports an Access Report to MS Word. It has to be in Word per gov't regulations, in Courier 12, and other certain formatting things which don't matter here.
Anyhow: the page header of the Word Doc must say:
Page X of Y
BLAH (MY OWN SENTENCE)
Date: (date function)
so i recorded a ton of macros to get it to do that, by the user hitting ctrl+alt+Q, running my crazy macro that opens the Page Header, puts in Page X of Y, pastes in the first sentence of the doc, then putting in the last "Date" line. that all works ok. BUT i cannot for the life of me get the font of the Page Header to be COURIER 12 pt. the whole doc is COURIER when i export it to Word so that's fine, but I can't get the Page Header to be COURIER 12 pt. I have this long bit of code that got generated during one of my Record Macro sessions (With Selection.Font) and it's placed before the code that creates the page header. I've also placed it in various other places, still without the results I want.
here's basically what i have so far (some insignificant parts cut out):
So how do i get the Page Header to be Courier 12? It seems like it's got to be an easy answer but I've spent way too much time messing around with this...
Thanks a ton--g
Anyhow: the page header of the Word Doc must say:
Page X of Y
BLAH (MY OWN SENTENCE)
Date: (date function)
so i recorded a ton of macros to get it to do that, by the user hitting ctrl+alt+Q, running my crazy macro that opens the Page Header, puts in Page X of Y, pastes in the first sentence of the doc, then putting in the last "Date" line. that all works ok. BUT i cannot for the life of me get the font of the Page Header to be COURIER 12 pt. the whole doc is COURIER when i export it to Word so that's fine, but I can't get the Page Header to be COURIER 12 pt. I have this long bit of code that got generated during one of my Record Macro sessions (With Selection.Font) and it's placed before the code that creates the page header. I've also placed it in various other places, still without the results I want.
here's basically what i have so far (some insignificant parts cut out):
Code:
'Selects the first paragraph (sentence) and cuts to get ready for pasting into the header
Dim rngParagraphs As Range
Set rngParagraphs = ActiveDocument.Range( _
Start:=ActiveDocument.Paragraphs(1).Range.Start, _
End:=ActiveDocument.Paragraphs(1).Range.End)
rngParagraphs.Select
Selection.Cut
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection.Font
.Name = "Courier"
.Size = 12
.Bold = False
.Italic = False
{etc}
End With
'Delete entire Page Header
Selection.Delete Unit:=wdCharacter, Count:=100
'Add first sentence: Page X of Y
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.TypeText Text:=" of "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages
'Add Second sentence: what the user selected
Selection.TypeParagraph
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeBackspace
'Add third sentence: Date
Selection.TypeParagraph
Selection.TypeText Text:="DATE: "
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Save
So how do i get the Page Header to be Courier 12? It seems like it's got to be an easy answer but I've spent way too much time messing around with this...
Thanks a ton--g