-
Open the Excel file containing the procedure that you want to add the PrintOut Method to. Decide which of the three PrintOut Methods is best to use in your procedure.
- 2
Open the VBA Editor to view your procedure. A shortcut to do this is to press "Alt" and "F11." In your procedure locate the area where you want to enter the PrintOut Method. Usually this method is located at or near the end of the procedure.
- 3
Enter the Workbooks' PrintOut Method command by typing the following:
Workbooks("Book1").PrintOut
This method prints all the worksheets in the Excel workbook. Replace "Book1" in quotations with the title of your workbook.
- 4
Enter the Worksheets' PrintOut Method syntax as in the example. This method prints only one worksheet in the Excel workbook. However, you can enter it as many times as you have worksheets to print.
Worksheets("Sheet1").PrintOut
Replace Sheet1 in quotations with the worksheet tab you want to print.
- 5
Enter the Worksheets' Range PrintOut Method syntax as in the example. This method prints a range, a selection of cells in a worksheet. You can enter it as many times as you have ranges to print.
Worksheets("Sheet1").Range("A1:A20").PrintOut
Replace Sheet1 in quotations with the worksheet tab, and replace A1:A20 with the range of cells you want to print.
用VBA实现在单击“打印”时,先弹出“消息框”后,点击“确认”后才开始打印?
If MsgBox("是否要打印?", vbYesNo) <> vbYes Then Exit Sub
使用循环
Do While Sheet4.Cells(1, 18) <> .Cells(m, 1)
Loop设置打印区域
Sub test()
ActiveWindow.View = xlPageBreakPreview
For b = [h65536].End(xlUp).Row To 2 Step -1
If Mid(Cells(b, 8), 1, 1) = "交" Then
If x = Empty Then
x = 1
y = 65536
Else
y = x
End If
For a = Range("a" & y).End(xlUp).Row To 2 Step -1
If Cells(a, 1) = "參考號:" Then
k = Range(Cells(a, 1), Cells(b, 8)).Address & "," & k
x = a
GoTo uk
End If
Next
End If
uk: Next
gu = 1
ActiveSheet.PageSetup.PrintArea = k
End Sub
看看k的值~
print k
How to Use Excel VBA for Printing
1