打印前很久,没有新的标题

时间:2016-12-12 21:53:49

标签: vba printing header

我有以下代码将特定标题打印到我要打印的每个页面。我需要很长时间才能打印,因为它可以再生40多张。在上面,项目编号永远不会改变,不知何故旧的项目编号(F6)保持在F6的新值之前。

Private Sub Workbook_BeforePrint(Cancel As Boolean)


Dim WS As Worksheet
For Each WS In Worksheets
Application.PrintCommunication = False
    With ActiveSheet.PageSetup.LeftHeaderPicture
        .Filename = "I:\Logo.png"
        .Height = 40
        .Width = 150

    End With
        ActiveSheet.PageSetup.LeftHeader = "&G" & vbCr & "" & vbCr & "&10Project: " & Worksheets(1).Range("F6").Text
        ActiveSheet.PageSetup.RightHeader = "p. "
Application.PrintCommunication = True
Next WS
End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

    Dim WS As Worksheet
    Application.PrintCommunication = False

    For Each WS In Worksheets

        With WS.PageSetup.LeftHeaderPicture
            .Filename = "I:\Logo.png"
            .Height = 40
            .Width = 150
        End With

        WS.PageSetup.LeftHeader = "&G" & vbCr & vbCr & _
                "&10Project: " & Worksheets(1).Range("F6").Text

        WS.PageSetup.RightHeader = "p. "

    Next WS

    Application.PrintCommunication = True
End Sub