Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Footer Macro Issues

    Hi Guys,

    I seem to be having an issue where everytime I create a macro to put something into the footer it wipes out what the macro already put in there.

    EG. I have to put a Document File Name and Page Number in the Macro but whatever is second in the macro will wipe out the first one.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,778
    Thanks
    0
    Thanked 162 Times in 150 Posts
    It would be easier to advise if you posted your macro code.

    PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #3
    New Lounger
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank You for getting back to me Paul.

    Since posting my requirements have changed alittle.

    Users open up this document and print it to be send out to customers. The idea is for them to hit the macro button and it print a clean document... the macro will then Watermarks 'ALL' pages with 'FILECOPY' and in the footer adds the filename without wiping out what is already there. Once it has done that it prints the file again.

    So to sum up in point form: (In one macro or as few as possible)

    1. Print a unedited copy.

    2. Watermark the document.

    3. Add Filename to the Footer of the document.

    4. Print an edited copy.


    First off I have no idea how to automate the printing. The code I have seems to only watermark the second page. I believe this is because the watermark users the header and my footer part of the macro is messing it up.

    Code:
    Private Sub HeaderEdit()
    ActiveDocument.Sections(1).Range.Select
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject6660509").Select
        Selection.ShapeRange.TextEffect.Text = "FILE COPY"
        Selection.ShapeRange.TextEffect.FontSize = 1
        Selection.ShapeRange.TextEffect.FontName = "Arial"
        Selection.ShapeRange.Line.Visible = False
        Selection.ShapeRange.Fill.Visible = True
        Selection.ShapeRange.Fill.Solid
        Selection.ShapeRange.Fill.ForeColor.RGB = RGB(128, 128, 128)
        Selection.ShapeRange.Fill.Transparency = 0.5
        Selection.ShapeRange.Rotation = 315
        Selection.ShapeRange.LockAspectRatio = True
        Selection.ShapeRange.Height = CentimetersToPoints(3.99)
        Selection.ShapeRange.Width = CentimetersToPoints(19.97)
        Selection.ShapeRange.WrapFormat.AllowOverlap = True
        Selection.ShapeRange.WrapFormat.Side = wdWrapNone
        Selection.ShapeRange.WrapFormat.Type = 3
        Selection.ShapeRange.RelativeHorizontalPosition = _
            wdRelativeVerticalPositionMargin
        Selection.ShapeRange.RelativeVerticalPosition = _
            wdRelativeVerticalPositionMargin
        Selection.ShapeRange.Left = wdShapeCenter
        Selection.ShapeRange.Top = wdShapeCenter
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub
    Sub FooterFileName()
    Dim oSection As Section
    Dim oHF As HeaderFooter
    Dim ExistingFooterText As String
    For Each oSection In ActiveDocument.Sections
    For Each oHF In oSection.Footers
    FooterEdit
    Next
    End Sub
    Sub FooterEdit()
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "FILENAME  \* Upper \p ", PreserveFormatting:=True
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub
    Last edited by Stock; 2014-04-09 at 00:49. Reason: Updated Information

  5. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,778
    Thanks
    0
    Thanked 162 Times in 150 Posts
    The entire process for what you've described could be accomplished with:
    Code:
    Sub PrintMe()
    Dim Shp As Shape, Sctn As Section, HdFt As HeaderFooter
    With ActiveDocument
      .Save
      .PrintOut
      With .Sections(1).Headers(wdHeaderFooterPrimary)
        Set Shp = .Shapes.AddTextEffect(0, "FILE COPY", "Arial", 1, False, False, 0, 0)
        With Shp
          .TextEffect.FontSize = 1
          .Line.Visible = False
          .Fill.Visible = True
          .Fill.Solid
          .Fill.ForeColor.RGB = RGB(128, 128, 128)
          .Fill.Transparency = 0.5
          .Rotation = 315
          .LockAspectRatio = True
          .Height = CentimetersToPoints(4)
          .Width = CentimetersToPoints(20)
          .WrapFormat.AllowOverlap = True
          .WrapFormat.Side = wdWrapNone
          .WrapFormat.Type = wdWrapNone
          .RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
          .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
          .Left = wdShapeCenter
          .Top = wdShapeCenter
        End With
      End With
      For Each Sctn In .Sections
        With Sctn.Footers(wdHeaderFooterPrimary)
          If .LinkToPrevious = False Then
            With .Range
              .InsertParagraphAfter
              .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, _
                Text:="FILENAME  \* Upper \p ", PreserveFormatting:=False
            End With
          End If
        End With
      Next
      .PrintOut
    End With
    End Sub
    Note: As coded, the macro only watermarks the first section's primary header, which may or may not be the first page and may or may not be linked to subsequent sections. Every Section can output as many as three headers and footers. The primary footers are updated for all footers in all Sections, though, and a similar process could be used for the watermarking. Also, running the code more than once on the same document will add multiple watermarks and filename fields...
    Last edited by macropod; 2014-04-09 at 20:00.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. The Following User Says Thank You to macropod For This Useful Post:

    Stock (2014-04-09)

  7. #5
    New Lounger
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you Paul,

    I had to put the Dim commands on separate lines for it to work but it works a charm.

    On my first page footer I have the the company name and page number. The Macro doesn't place the filename in there which I would have hoped it would - No watermark on the first page is ok but is there a way to have it placed in the footer and preserving the current footer?

    I owe you two coffees for this :P

  8. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,778
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Quote Originally Posted by Stock View Post
    I had to put the Dim commands on separate lines for it to work but it works a charm.

    On my first page footer I have the the company name and page number. The Macro doesn't place the filename in there which I would have hoped it would - No watermark on the first page is ok but is there a way to have it placed in the footer and preserving the current footer?
    The first issue suggests there is something wrong with your office installation. Try repairing Office (via Programs & Features > Microsoft Office > Change in the Windows Control Panel). Regarding the second issue, that suggests you're using a 'different first page' and/or 'different odd and even' page layout, which could explain why there's no footer there.
    Last edited by macropod; 2014-04-09 at 20:03. Reason: Clarification
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #7
    New Lounger
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've been able to fix up the macro so it posts in the first page as below:

    Code:
    Sub PrintMe()
    ' PrintMe Macro
    Dim Shp As Shape
    Dim Sctn As Section
    Dim HdFt As HeaderFooter
    Dim oSection As Section
    Dim oHF As HeaderFooter
    Dim ExistingFooterText As String
    With ActiveDocument
      .Save
      .PrintOut
      With .Sections(1).Headers(wdHeaderFooterPrimary)
        Set Shp = .Shapes.AddTextEffect(0, "FILE COPY", "Arial", 1, False, False, 0, 0)
        With Shp
          .TextEffect.FontSize = 1
          .Line.Visible = False
          .Fill.Visible = True
          .Fill.Solid
          .Fill.ForeColor.RGB = RGB(128, 128, 128)
          .Fill.Transparency = 0.5
          .Rotation = 315
          .LockAspectRatio = True
          .Height = CentimetersToPoints(4)
          .Width = CentimetersToPoints(20)
          .WrapFormat.AllowOverlap = True
          .WrapFormat.Side = wdWrapNone
          .WrapFormat.Type = wdWrapNone
          .RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
          .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
          .Left = wdShapeCenter
          .Top = wdShapeCenter
      End With
      End With
      For Each Sctn In .Sections
        With Sctn.Footers(wdHeaderFooterPrimary)
          If .LinkToPrevious = False Then
            With .Range
              .InsertParagraphAfter
              .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, _
                Text:="FILENAME  \* Upper \p ", PreserveFormatting:=False
            End With
          End If
        End With
      Next
    For Each oSection In ActiveDocument.Sections
    For Each oHF In oSection.Footers
    Next
    Next
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "FILENAME  \* Upper \p ", PreserveFormatting:=True
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
      .PrintOut
    End With
    End Sub
    Because I can't seem to get the Watermark to work on the first page (possible Word needs repairing). Is there a way to bound the words FILE COPY to the top left of the document (not in the header but the main body of the document).

    Right Now it seems to post it whereever the printme macro finishes. Here's what I have created:

    Code:
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
            1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
            wdAutoFitFixed
        With Selection.Tables(1)
            If .Style <> "Table Grid" Then
                .Style = "Table Grid"
            End If
            .ApplyStyleHeadingRows = True
            .ApplyStyleLastRow = False
            .ApplyStyleFirstColumn = True
            .ApplyStyleLastColumn = False
            .ApplyStyleRowBands = True
            .ApplyStyleColumnBands = False
        End With
        Selection.Font.Size = 10
        Selection.Font.Bold = wdToggle
        Selection.Font.Color = wdColorRed
        Selection.TypeText Text:="FILE COPY"
        Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Inserting that at the end of the Print Me Macro seems to place it wherever.
    Last edited by Stock; 2014-04-09 at 20:46.

  10. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,778
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Try this version - you'll get the watermark & footer on every page:
    Code:
    Sub PrintMe()
    Dim Shp As Shape, Sctn As Section, HdFt As HeaderFooter
    With ActiveDocument
      .Save
      .PrintOut
      For Each Sctn In .Sections
        For Each HdFt In Sctn.Headers
          If HdFt.LinkToPrevious = False Then
            Set Shp = HdFt.Shapes.AddTextEffect(0, "FILE COPY", "Arial", 1, False, False, 0, 0)
            With Shp
              .TextEffect.FontSize = 1
              .Line.Visible = False
              .Fill.Visible = True
              .Fill.Solid
              .Fill.ForeColor.RGB = RGB(128, 128, 128)
              .Fill.Transparency = 0.5
              .Rotation = 315
              .LockAspectRatio = True
              .Height = CentimetersToPoints(4)
              .Width = CentimetersToPoints(20)
              .WrapFormat.AllowOverlap = True
              .WrapFormat.Side = wdWrapNone
              .WrapFormat.Type = wdWrapNone
              .RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
              .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
              .Left = wdShapeCenter
              .Top = wdShapeCenter
            End With
          End If
        Next
        For Each HdFt In Sctn.Footers
          If HdFt.LinkToPrevious = False Then
            If .LinkToPrevious = False Then
              With .Range
                .InsertParagraphAfter
                .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, _
                  Text:="FILENAME  \* Upper \p ", PreserveFormatting:=False
              End With
            End If
          End If
        Next
      Next
      .PrintOut
    End With
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. The Following User Says Thank You to macropod For This Useful Post:

    Charles Kenyon (2014-04-10)

Posting Permissions

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