-1
我有一个很多工作表的excel工作簿。数据需要转换为PDF。Excel到PDF转换
现在,有一些图像必须出现在PDF的页眉和页脚中。此外页码需要打印。
你能建议最好的方法来处理这个问题吗?我在VBA上工作。任何人都可以告诉如果这可以使用Excel - VBA来实现吗?
非常感谢。
我有一个很多工作表的excel工作簿。数据需要转换为PDF。Excel到PDF转换
现在,有一些图像必须出现在PDF的页眉和页脚中。此外页码需要打印。
你能建议最好的方法来处理这个问题吗?我在VBA上工作。任何人都可以告诉如果这可以使用Excel - VBA来实现吗?
非常感谢。
试试这个办法,我已经..解决我的问题与此,你还没有发布任何具体的细节......你需要弄清楚如何使用此代码...
Private Sub CommandButton1_Click()
Dim wksAllSheets As Variant ' define a worksheet object arrray
Dim wksSheet1 As Worksheet ' a dummy variable
Dim strFilename As String ' file name
Dim strFilepath As String ' file path, default is the current working dir
' file destination folder name...
strFilepath = "C:\Reports"
' check if folder exist or not, if doesn't then creates it otherwise ignore it
If Len(Dir(strFilepath, vbDirectory)) = 0 Then
MkDir strFilepath
End If
strFilepath = strFilepath & "\"
' Initialize variables
wksAllSheets = Array("Strategy", "Summary", "Trades", "TradeAnalysis") '' array of sheetName i want to save as pdf
strFilename = "outputFileName.pdf"
'''''''''''''''''''''''''''''''''''' Here I am setting the page layout for each sheet, use if you need '''''''''''''''''''''''''''''''''''''''''''''''''
Set wksSheet1 = ThisWorkbook.Sheets("Strategy")
' change the page setup Attributes of 'Strategy' sheet object
With wksSheet1.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperFanfoldLegalGerman
.Zoom = 85
.TopMargin = 0
.BottomMargin = 0
.RightMargin = 0
.LeftMargin = 0
.HeaderMargin = 0
.FooterMargin = 0
End With
' change the page setup Attributes of 'Summary' sheet object
Set wksSheet1 = ThisWorkbook.Sheets("Summary")
With wksSheet1.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.Zoom = 90
.TopMargin = 0.25
.BottomMargin = 0.25
.RightMargin = 0.25
.LeftMargin = 0.25
.HeaderMargin = 0.25
.FooterMargin = 0.25
End With
' change the page setup Attributes of 'Trades' sheet object
Set wksSheet1 = ThisWorkbook.Sheets("Trades")
With wksSheet1.PageSetup
.CenterHeader = "Trades"
.Orientation = xlLandscape
.PrintArea = "$B$2:$U$321" ' pass it as a parameter
.Zoom = 100
.PaperSize = xlPaperLegal
.PrintTitleRows = wksSheet1.Rows(2).Address
End With
' change the page setup Attributes of 'TradeAnalysis' sheet object
Set wksSheet1 = ThisWorkbook.Sheets("TradeAnalysis")
With wksSheet1.PageSetup
.CenterHeader = "TradeAnalysis"
.Orientation = xlPortrait
.LeftMargin = 0.25
.RightMargin = 0.25
.Zoom = 100
End With
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Save all the sheet in the array as one single PDF file
ThisWorkbook.Sheets(wksAllSheets).Select
wksSheet1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strFilepath & strFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
'update the wksSheet1 object in with the next entry from wksAllSheets array of object
wksSheet1.Select
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
和这是一个reference
它工作吗? –