First of all I would like to apologise to Fumei (Gerry) for being short with him. I appreciate you are trying to help me and I was out of order being rude to you.
I appreciate your help.
The code that i'm trying to execute at the moment looks something like this:
Private Sub Document_Print()
Macro1
ActiveDocument.Printout, , , , , , , 1
Macro2
Macro3
ActiveDocument.Printout , , , , , , , 1
Macro2
Macro4
ActiveDocument.Printout, , , , , , , 1
Macro2
End Sub
The Code for Macro1 is:
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
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, _
"Patient Copy", "Times New Roman", 1, False, False, 0, 0).Select
Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"
Selection.ShapeRange.TextEffect.NormalizedHeight = False
Selection.ShapeRange.Line.Visible = False
Selection.ShapeRange.Fill.Visible = True
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
Selection.ShapeRange.Fill.Transparency = 0.5
Selection.ShapeRange.Rotation = 315
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = CentimetersToPoints(3.07)
Selection.ShapeRange.Width = CentimetersToPoints(18.41)
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
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
This is the same for both macros 3 & 4 except the watermark uses different text.
Macro 2 which removes the watermark looks like:
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
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
The macros were recoreded using the record macro feature in word and run fine when executed manually but I would like them to run when the document is sent for printing. Following the advice from Fumei and Gavona I think my code should be similar to :
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Macro1
ActiveDocument.Printout , , , , , , , 1
Macro2
Macro3
ActiveDocument.Printout , , , , , , , 1
Macro2
Macro4
ActiveDocument.Printout , , , , , , , 1
Macro2
End Sub
with:
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub
thrown in somewhere but i'm unsure where. I would be grateful if someone could explain how all this code comes together as i'm new to any programming.
Thank you