我发现了一个将Excel工作表打印到PDF的宏,我希望能够跨多个工作表执行此操作,而不必使用工作表名称但使用工作表索引。 我希望根据每个工作表中的范围保存pdf(此范围在所有工作表上都相同)。
继承人我所拥有的:
Sub exceltoPDF1()
'Saves the excel print area to a PDF file
Dim fp As String
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Worksheets(1).Activate
Set rng = Worksheets(1).Range("A1")
'\\MNACPFS01\Home\sramdeo\Desktop\stuff
i = rng
fp = "\\MNACPFS01\Home\sramdeo\Desktop\stuff "
'fp = "H:\2013_FY148\07_OCT13\4. PROGRAM DOCS\APR\ " & "rng.pdf"""
Set wb = ActiveWorkbook
Set ws = Worksheets(1)
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=i, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
答案 0 :(得分:0)
这将使用工作表的索引传递工作簿wb
中包含的所有工作表:
Sub exceltoPDF1()
'Saves the excel print area to a PDF file
Dim fp As String
Dim wb As Workbook
Dim rng As Range
Set wb = ActiveWorkbook
Dim intWS As Integer
For intWS = 1 To wb.Worksheets.Count
With wb.Worksheets(intWS)
Set rng = .Range("A1")
'\\MNACPFS01\Home\sramdeo\Desktop\stuff
i = rng
fp = "\\MNACPFS01\Home\sramdeo\Desktop\stuff "
'fp = "H:\2013_FY148\07_OCT13\4. PROGRAM DOCS\APR\ " & "rng.pdf"""
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=i, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
Next intWS '<--- Change this from "i" to "intWS"
End Sub
答案 1 :(得分:0)
Sub Cetak_Sampul()
Dim StartmRow As Integer
Dim EndmRow As Integer
Dim Msgm As String
Dim a As Integer
Sheets("Cvr").Activate
StartmRow = Range("RA")
EndmRow = Range("RW")
If StartmRow > EndmRow Then
Msgm = "ERROR" & vbCrLf & "Record awal ga boleh lebih dari record akhir!"
MsgBox Msgm, vbCritical, APPNAME
End If
For a = StartmRow To EndmRow
Range("ON") = a
If Range("PR") Then
ActiveSheet.PrintPreview
Else
ActiveSheet.PrintOut
End If
Next a
End Sub
(如何以PDF格式打印,文件名保存在范围内(&#34; ON&#34;) 该文件为here 修剪&#39; S