BeforePrint Event
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: BeforePrint Event

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I have the following code in the BeforePrint section of VBE. The function works correctly when I print from the worksheet, but does not update the header when I print from a macro - even though it is accessing the event (I checked with debugger) Anyone have any ideas to correct this? Thanks!

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim Title
    Title = ActiveSheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
    With ActiveSheet.PageSetup
    .LeftFooter = ActiveWorkbook.FullName
    .CenterHeader = Title
    End With
    End Sub

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You could split this macro out to call the procedure from a normal module. Something along the lines as follows:

    In the this workbook module:
    Code:
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.Run ("setUp")
    End Sub
    And in normal modules:
    Code:
    Private Sub setUp()
    Dim Title
    Title = ActiveSheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
    With ActiveSheet.PageSetup
    .LeftFooter = ActiveWorkbook.FullName
    .CenterHeader = Title
    End With
    End Sub
    
    Sub Othermacro()
    Application.Run ("setUp")
    ActiveSheet.PrintOut
    End Sub
    Hopefully this helps.

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Thanks Nate, I went with code in a normal module to put the header & footer on all sheets before I print any:

    For Each Worksheet In Worksheets
    Dim Title
    Title = "&B &14" & Worksheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
    With Worksheet.PageSetup
    .LeftFooter = ActiveWorkbook.FullName
    .CenterHeader = Title
    End With
    Next Worksheet

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com