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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Template

Status
Not open for further replies.

GingerR

MIS
Apr 17, 2001
3,134
US
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):
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
 
Hi Ginger,

When you delete the selection, you lose the font setting, so try swapping round the delete and the font setting ..

Code:
[blue]:
:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
  

    'Delete entire Page Header
    Selection.Delete Unit:=wdCharacter, Count:=100
    
    With Selection.Font
        .Name = "Courier"
        .Size = 12
        .Bold = False
        .Italic = False
        (etc)
     End With
 
:
:[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Hi Tony-Thanks. But I still have a problem--the line that I paste in, always comes up with Times New Roman no matter what I do. Even if I put the whole section of With Selection.Font before and/or after it, it still comes up as Times New Roman. I have the With Selection.Font bit copied in my code like 5 times now but with no luck. The line that's being copied is in Courier 12. Any suggestions?

Thanks a ton--g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top