EXCEL VBA 工作表放入單一頁面打印問題?

2016-12-19 6:12 pm
我想用VBA按我要求次序打印一批EXCEL, 但當設定把工作表放入單一頁面打印出問題.
因VBA的With要輸入worksheet的名稱, 但每個excel的頁名都不同, 我嘗試用ActiveSheet代替也不行.
請高手大大指教怎解決

Set rrr = CreateObject("Scripting.FileSystemObject")


Workbooks.Open Filename:=(AAA + "\" + Cells(Range("L2").Value, 2).Text + "")
Range("C:E").Columns.AutoFit

Application.PrintCommunication = False
With ActiveSheet
.Zoom = False
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = 0
End With
Application.PrintCommunication = True

ActiveWindow.SelectedSheets.printout To:=1, Copies:=1, Collate:=True

ActiveWindow.Close saveChanges:=False

回答 (1)

2016-12-20 12:13 pm
如果是很多個工作簿很多個工作表
Sub test()
DirPath = ThisWorkbook.Path
fs = Dir(DirPath & "\*.xls*")
Do Until fs = ""
r = r + 1
Fname = DirPath & "\" & fs
If Fname <> "False" Then Workbooks.Open Fname

For i = 1 To Sheets.Count
Sheets(i).Select
''加入錄製單一列印頁面的巨集程序
Next
Workbooks(fs).Close False
fs = Dir
Loop
End Sub

如果是工作簿內有很多個工作表
For i = 1 To Sheets.Count
''With Sheets(i)
Sheets(i).Select
''加入錄製單一列印頁面的巨集程序
Next


收錄日期: 2021-05-03 13:49:48
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20161219101201AAh3NRt

檢視 Wayback Machine 備份