2016-11-08 93 views
0

我有一個非常具體的電子表格,其中包含所有員工的工資/獎金。每位員工都有4行(薪金/獎金/薪金%增值/獎金佔工資的百分比)。我遇到的問題是,如果一些管理人員將其員工切換到多個頁面,所以我將其切換爲適合1 x 1,但現在顯然它過於精簡。有沒有辦法讓宏組以4行的形式打印?或者可以這樣做,它爲同一頁面上的每個員工打印4行(薪水/獎金/工資%工資的百分比/獎金)預先感謝您!VBA 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 

回答

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