Chisholm
08-13-2008, 01:05 PM
I've been trying to get the following code to format a report. The
"sub watermark" routine is adding the watermark to all pages except the cover page.
I'd like to add it to all pages.
Additionally, I'd like the footers to have a line over them, how do I code that?
Sub Format_Report()
'Create Header
Call Header
'Remover logo header from cover page
Call Remove_Cover_Page_Header
'Create Footer
Call Footer
'Adjust header and footer margins.
Call Set_Margins
Selection.MoveDown unit:=wdScreen, Count:=2
'Create Footer on other pages
Call Other_Footer
'Format SME logo on cover
Call Format_Cover_Logo
'Create Watermark
Call Watermark
End Sub
Sub Footer()
'Creates SME footer on all pages of the report
WordBasic.ViewFooterOnly
Selection.Font.Name = "Copperplate Gothic Light"
Selection.Font.Size = 11
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:= _
"711 CLAYCRAFT ROAD COLUMBUS, OHIO 43230 PH: (614) 866-7554 F"
Selection.TypeText Text:="X: (614) 866-8241"
Selection.TypeParagraph
Selection.TypeText Text:="OH LICENSE # 12526 EQUAL OPPUTUNITY EMPLOYER"
Selection.MoveLeft unit:=wdCharacter, Count:=26
Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
Selection.MoveUp unit:=wdLine, Count:=2
'Format the footer
WordBasic.ViewFooterOnly
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphCenter
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub Header()
'Adds the SME logo header to the report
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
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:= _
"G:\Leibold\Various Items\SME LOGO 2.jpg", LinkToFile:=False, _
SaveWithDocument:=True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub
Sub Remove_Cover_Page_Header()
'
' Remove_Cover_Page_Header Macro
'
'
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
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.43)
.LeftMargin = InchesToPoints(0.75)
.RightMargin = InchesToPoints(0.17)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
End Sub
Sub Set_Margins()
'
' Set_Margins Macro
'
'
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.75)
.RightMargin = InchesToPoints(0.17)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.2)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.2)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
End Sub
Sub Other_Footer()
'
' Other_Footer Macro
'
'
WordBasic.ViewFooterOnly
Selection.Font.Name = "Copperplate Gothic Light"
Selection.TypeText Text:= _
"711 CLAYCRAFT ROAD COLUMBUS, OHIO 43230 PH: (614) 866-7554 F"
Selection.TypeText Text:="X: (614) 866-8241"
Selection.TypeParagraph
Selection.TypeText Text:="OH LICENSE # 12526 EQUAL OPPUTUNITY EMPLOYER"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphCenter
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub Format_Cover_Logo()
'Selects SME logo on cover page,
'Locks aspect ratio, sets width to 350, then centers the logo.
Dim Wid As Integer
Dim Original_Width As Integer
Dim Original_Height As Integer
Dim Aspect_Ratio As Double
'Set variable Wid as desired Width
Wid = 350
'Find original aspect ratio
Set DocThis = ActiveDocument
Original_Width = DocThis.InlineShapes(1).Width
Original_Height = DocThis.InlineShapes(1).Height
Aspect_Ratio = Original_Height / Original_Width
DocThis.InlineShapes(1).Width = 350
DocThis.InlineShapes(1).Height = 350 * Aspect_Ratio
DocThis.InlineShapes(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub
Sub Watermark()
'
' Macro5 Macro
'
Selection.EscapeKey
Selection.EscapeKey
'ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"G:\Leibold\Various Items\Sinusoid_Made.JPG", LinkToFile:=False, _
SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark19162281"
Selection.ShapeRange.PictureFormat.Brightness = 0.85
Selection.ShapeRange.PictureFormat.Contrast = 0.15
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(4.69)
Selection.ShapeRange.Width = InchesToPoints(4.69)
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 watermark" routine is adding the watermark to all pages except the cover page.
I'd like to add it to all pages.
Additionally, I'd like the footers to have a line over them, how do I code that?
Sub Format_Report()
'Create Header
Call Header
'Remover logo header from cover page
Call Remove_Cover_Page_Header
'Create Footer
Call Footer
'Adjust header and footer margins.
Call Set_Margins
Selection.MoveDown unit:=wdScreen, Count:=2
'Create Footer on other pages
Call Other_Footer
'Format SME logo on cover
Call Format_Cover_Logo
'Create Watermark
Call Watermark
End Sub
Sub Footer()
'Creates SME footer on all pages of the report
WordBasic.ViewFooterOnly
Selection.Font.Name = "Copperplate Gothic Light"
Selection.Font.Size = 11
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:= _
"711 CLAYCRAFT ROAD COLUMBUS, OHIO 43230 PH: (614) 866-7554 F"
Selection.TypeText Text:="X: (614) 866-8241"
Selection.TypeParagraph
Selection.TypeText Text:="OH LICENSE # 12526 EQUAL OPPUTUNITY EMPLOYER"
Selection.MoveLeft unit:=wdCharacter, Count:=26
Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
Selection.MoveUp unit:=wdLine, Count:=2
'Format the footer
WordBasic.ViewFooterOnly
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphCenter
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub Header()
'Adds the SME logo header to the report
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
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:= _
"G:\Leibold\Various Items\SME LOGO 2.jpg", LinkToFile:=False, _
SaveWithDocument:=True
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub
Sub Remove_Cover_Page_Header()
'
' Remove_Cover_Page_Header Macro
'
'
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
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.43)
.LeftMargin = InchesToPoints(0.75)
.RightMargin = InchesToPoints(0.17)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
End Sub
Sub Set_Margins()
'
' Set_Margins Macro
'
'
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.75)
.RightMargin = InchesToPoints(0.17)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.2)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.2)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
End Sub
Sub Other_Footer()
'
' Other_Footer Macro
'
'
WordBasic.ViewFooterOnly
Selection.Font.Name = "Copperplate Gothic Light"
Selection.TypeText Text:= _
"711 CLAYCRAFT ROAD COLUMBUS, OHIO 43230 PH: (614) 866-7554 F"
Selection.TypeText Text:="X: (614) 866-8241"
Selection.TypeParagraph
Selection.TypeText Text:="OH LICENSE # 12526 EQUAL OPPUTUNITY EMPLOYER"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphCenter
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub Format_Cover_Logo()
'Selects SME logo on cover page,
'Locks aspect ratio, sets width to 350, then centers the logo.
Dim Wid As Integer
Dim Original_Width As Integer
Dim Original_Height As Integer
Dim Aspect_Ratio As Double
'Set variable Wid as desired Width
Wid = 350
'Find original aspect ratio
Set DocThis = ActiveDocument
Original_Width = DocThis.InlineShapes(1).Width
Original_Height = DocThis.InlineShapes(1).Height
Aspect_Ratio = Original_Height / Original_Width
DocThis.InlineShapes(1).Width = 350
DocThis.InlineShapes(1).Height = 350 * Aspect_Ratio
DocThis.InlineShapes(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub
Sub Watermark()
'
' Macro5 Macro
'
Selection.EscapeKey
Selection.EscapeKey
'ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"G:\Leibold\Various Items\Sinusoid_Made.JPG", LinkToFile:=False, _
SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark19162281"
Selection.ShapeRange.PictureFormat.Brightness = 0.85
Selection.ShapeRange.PictureFormat.Contrast = 0.15
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(4.69)
Selection.ShapeRange.Width = InchesToPoints(4.69)
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