Consulting

Results 1 to 7 of 7

Thread: Header/footer Word macro

  1. #1
    VBAX Newbie
    Joined
    May 2013
    Posts
    2
    Location

    Header/footer Word macro

    I'm hoping to use a header and footer on regular Word reports. This is what I have but there is at least one error here for above my message, I get - [Type text] Which I want to remove.

    Very grateful for guidance, experts.
    My macro is -
    [vba]
    Sub AhHeadAnFeet()
    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
    MsgBox "We are running the new head and footers macro, gracias!"
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Application.Templates( _
    "C:\Users\paul\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Built-In Building Blocks.dotx" _
    ).BuildingBlockEntries(" Blank").Insert Where:=Selection.Range, RichText _
    :=False
    Selection.TypeText Text:="weekly statistics | numbers for this week in May 2013 | "
    Application.Templates( _
    "C:\Users\paul\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Built-In Building Blocks.dotx" _
    ).BuildingBlockEntries("Plain Number").Insert Where:=Selection.Range, _
    RichText:=True
    Selection.TypeText Text:=" of "
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "NUMPAGES ", PreserveFormatting:=True
    Selection.TypeText Text:=Chr(11) & _
    "..........................................................."
    Selection.TypeText Text:= _
    "............................................................"
    Selection.TypeText Text:="..................."
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Font.Name = "Bradley Hand ITC"
    End Sub

    [/vba]

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Why don't you create a template with the required content and formatting? No code required.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    May 2013
    Posts
    2
    Location
    Thanks, Paul. Yes, a good idea, but isn't it too easy? Shouldn't I find out what's wrong with my VBA? I haven't used it for a few years, but thought I should get it going again, and macros seem to be a good place to start.

    And this is a useful macro I could often use. The error must be quite simple, but I can't find it.

    Thanks very much for the good alternative. Cheers paul

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by zonkd
    a good idea, but isn't it too easy? Shouldn't I find out what's wrong with my VBA?
    There's an old adage: who cares what the problem was when you've already got the answer.

    FWIW:
    [vba]Sub AhHeadAnFeet()
    With ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary).Range
    .Font.Name = "Bradley Hand ITC"
    .Text = "weekly statistics | numbers for this week in May 2013 | " & vbTab & "Page "
    .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="PAGE", Preserveformatting:=False
    .InsertAfter " of "
    .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="NUMPAGES", Preserveformatting:=False
    .InsertAfter Chr(11) & "..........................................................." & _
    ".......................................................................... ....."
    End With
    End Sub[/vba]
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Why on earth do you want to use code to put in a lot of spaces..................................................................... ........................................................................... ........................................................................... ........................................................................... .................................................................and why do you want to put in a lot of spaces at all?

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Gerry,

    They're periods ...

    Maybe the zonkd is inputting them because he/she has never heard of tab stops with dot leaders.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Ah. Ooops, I did not notice the string literals. In some ways it is even more odd.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •