2017-09-25 57 views
-1

私は多くのシートを持つExcelブックを持っています。データをPDFに変換する必要があります。ExcelからPDFへの変換

ここでは、PDFのヘッダーとフッターにいくつかのイメージが存在する必要があるということです。また、ページ番号を印刷する必要があります。

これを処理するための最良の方法を提案できますか?私はVBAに取り組んでいます。これがExcel - VBAを使って実現できるかどうか誰にでも分かりますか?

ありがとうございます。

答えて

0

あなたが任意の特定の詳細を投稿していないとして、このアプローチを試してみてください、私はあなたがこのコードを使用する方法を理解する必要があります... ..これで私の問題を解決した...

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

+0

それは働いたのですか? –