我正在尝试遍历所有活动表并将它们另存为单独的PDF。
dim ws as worksheet
dim path as string
...
For Each ws In ActiveWindow.SelectedSheets
ws.ExportAsFixedFormat _
xlTypePDF, _
Filename:=path & ws.Name, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenafterPublish:=False
Next
这类作品:
在正确的文件夹中为每个选定的图纸创建PDF文件...但是...
这些PDF文件的内容完全相同。这是每次打印的活动表,但使用不同的文件名。
如何解决此问题?请记住,我只希望打印选定的图纸。
编辑:我太新了,不能投票。感谢您的回答!
答案 0 :(得分:0)
Option Explicit
Sub Save_SelectedSheets_AsPdf()
Dim ws As Worksheet
Dim path As String
Dim actSheet As Worksheet
'...
Set actSheet = ActiveSheet
For Each ws In ActiveWindow.SelectedSheets
ws.Select
ws.ExportAsFixedFormat _
xlTypePDF, _
Filename:=path & ws.Name, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenafterPublish:=False
Next
actSheet.Select
End Sub
Sub Create_5_Sheets_and_name_them()
Dim iCt As Integer
For iCt = 2 To 5
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = "Sh" & iCt
Range("A1").Value = ActiveSheet.Name
Next iCt
End Sub
答案 1 :(得分:0)
打印之前,您需要Select
表。
只需在ws.Select
前面添加命令ws.ExportAsFixedFormat
,它将起作用:
For Each ws In ActiveWindow.SelectedSheets
ws.Select '<-- the only thing you have to add.
ws.ExportAsFixedFormat _
xlTypePDF, _
Filename:=path & ws.Name, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenafterPublish:=False
Next
为此:
Application.ScreenUpdating = False
,然后在循环结束时将其设置回Application.ScreenUpdating = True
循环。 Dim currentlySelectedSheet As Worksheet: Set currentlySelectedSheet = ActiveSheet
获取当前活动的工作表,而在循环结束时,只需使用{{ 1}},这样用户在运行宏时就不会在屏幕上看到任何变化。答案 2 :(得分:0)