【问题标题】:VBA Printing in Groups of 4 Rows以 4 行为一组进行 VBA 打印
【发布时间】:2016-11-08 11:57:09
【问题描述】:

我有一个非常具体的电子表格,其中包含所有员工的工资/奖金。每个员工自己有 4 行(工资/奖金/工资 % Delta / 奖金占工资的百分比)。我遇到的问题是,如果它进入多个页面,一些经理会切断他们的员工,所以我将它切换为适合 1 x 1,但现在显然它太浓缩了。有没有办法以 4 行为一组进行宏打印?或者也许让它在同一页面上为每个员工打印 4 行(工资/奖金/工资 % 增量/奖金占工资的百分比)提前谢谢!

Private Sub CommandButton1_Click()
Dim Sel_Manager As String
'Specify headers to be repeated at the top
With ActiveSheet.PageSetup
        .PrintTitleRows = "$5:$10"
        .PrintTitleColumns = "$B:$M"
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
End With

'Manager selection through simple Inputbox
 Sel_Manager = ComboBox1
'Insert autofilter for worksheet
Cells.Select
Selection.AutoFilter
'Select manager defined in inputbox
ActiveSheet.Range("B10", Range("M10").End(xlDown)).AutoFilter Field:=1, Criteria1:=Sel_Manager
 'Select range to be printed and specify manager in filename
ActiveSheet.Range("B10", Range("M10").End(xlDown)).Select

Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Sel_Manager + ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

  ActiveSheet.ShowAllData

End Sub

【问题讨论】:

    标签: vba excel printing


    【解决方案1】:

    我想我有更好的解决方案给你。您可以每 x 行在页面上拆分打印区域。看看这个例子,每个页面有 100 行:

    LastRow = Sheets("Raport").Range("B" & Rows.Count).End(xlUp).Row
    Sheets("Raport").PageSetup.PrintArea = "$A$1:$G$" & LastRow
    
    t = 4 ' number of title rows
    r = 96 ' number of rows on one page (without title rows)
    nPages = Application.RoundUp((LastRow - 4) / 96, 0) 'nPages gives you number of pages. 
    Sheets("Raport").ResetAllPageBreaks
    Sheets("Raport").VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1 ' this may not be necessary for your data
    
    On Error Resume Next
    If nPages > 1 Then
        For i = 1 To nPages - 1
            ActiveSheet.HPageBreaks.Add Before:=ActiveSheet.Range("A" & 5 + i * 96)
            Set ActiveSheet.HPageBreaks(i).Location = Range("A" & 5 + i * 96)
        Next i
    Else
        ActiveSheet.HPageBreaks(1).DragOff Direction:=xlDown, RegionIndex:=1
    End If
    On Error GoTo 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 2015-11-08
      相关资源
      最近更新 更多