VBA Select 打印文件夹中的文件时的打印机
VBA Select Printer when Printing files within a folder
我有这个脚本可以打印一个文件夹中的所有文件,但它总是选择默认打印机,有没有办法指定我希望它在 VBA 中打印的打印机名称代码?
Sub CommandButton1_Click()
Dim wb As Workbook, ws As Worksheet
Dim FileName As String, Path As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
Path = "Z:\Customer Operations21\Despatches\*.csv"
FileName = Dir(Path, vbNormal)
Do Until FileName = ""
Application.DisplayAlerts = False
Workbooks.Open Left(Path, Len(Path) - 5) & FileName
Columns("A:H").AutoFit
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.PrintOut
Next
wb.Close
FileName = Dir()
Loop
End Sub
非常感谢任何帮助:)
如果您想在 运行 时 over-ride 默认值,请在您的代码中包含此行:
Application.Dialogs(xlDialogPrinterSetup).Show
我有这个脚本可以打印一个文件夹中的所有文件,但它总是选择默认打印机,有没有办法指定我希望它在 VBA 中打印的打印机名称代码?
Sub CommandButton1_Click()
Dim wb As Workbook, ws As Worksheet
Dim FileName As String, Path As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
Path = "Z:\Customer Operations21\Despatches\*.csv"
FileName = Dir(Path, vbNormal)
Do Until FileName = ""
Application.DisplayAlerts = False
Workbooks.Open Left(Path, Len(Path) - 5) & FileName
Columns("A:H").AutoFit
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.PrintOut
Next
wb.Close
FileName = Dir()
Loop
End Sub
非常感谢任何帮助:)
如果您想在 运行 时 over-ride 默认值,请在您的代码中包含此行:
Application.Dialogs(xlDialogPrinterSetup).Show