ray88’s diary

お仕事で困ったとき用の自分用の覚書

Excel VBA Excel→PDFファイルへ変換②

Sub outputPDF()

    Dim strPdfPath As String
    Dim wb As Workbook
    Dim strSheetName As String
    Dim strExcelPath As String
    
    strExcelPath = "C:\Users\デスクトップ\テスト\サービス請求書1.xlsx"
    strPdfPath = ThisWorkbook.Path & "\201603請求書_株式会社ホゲホゲ御中.pdf"
    
    Set wb = Workbooks.Open(strExcelPath)
    
        With wb.Sheets("サービス請求書").PageSetup
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 1
        End With
    
    wb.Sheets("サービス請求書").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPdfPath
    wb.Close
    
    Set wb = Nothing   
End Sub