030 大量のExcelをPDF変換


030 大量のExcelをPDF変換のサンプルコードは下記です。
VBA画面で貼り付けてください^^
分からないこと等あったら、ご連絡よろしくお願いします!!
※素人の私が作っているので、もっと良い書き方たくさんあると思いますが、
 ご了承ください!

--------------------------------------------------------------------------------

Dim strPath_1 As String, strPath_2 As String, buf As String, ExcelFilename As String, PdfFilename As String, saveFilename As String
Dim cnt As Long

Sub ExceltoPDF()

Application.ScreenUpdating = False

strPath_1 = ActiveWorkbook.Path & "\Excel\"
strPath_2 = ActiveWorkbook.Path & "\PDF\"
 

buf = Dir(strPath_1 & "*.xls*") 'ファイル名取得
 
If buf <> "" Then
    cnt = 0
    Do While buf <> ""
        ExcelFilename = buf
        Workbooks.Open strPath_1 & buf 'ファイルを開く
     
        PdfFilename = Left(ExcelFilename, InStr(ExcelFilename, ".") - 1) & ".PDF" 'Excelファイル名でPDF変換
        saveFilename = strPath_2 & PdfFilename
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFilename 'PDF形式で保存
     
        Workbooks(buf).Close
     
        buf = Dir()
        cnt = cnt + 1
    Loop
 
    Application.ScreenUpdating = True
 
    MsgBox cnt & "件、変換完了しました(^O^)"

Else
    MsgBox "Excelファイルがありません(泣)"
End If

End Sub

コメント