0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

フォルダにあるExcelファイルを全てpdfへ変換するVBS

Posted at

フォルダにエクセルとvbsファイルを置いてvbsを実行するとフォルダ内のエクセルを全てpdfへ変換(ブック全体)

ExcelToPDF.vbs
' エクセルを開くためのオブジェクト
Set ExApp = CreateObject("Excel.Application")
' ファイル操作のためのオブジェクト
Set FSO = CreateObject("Scripting.FileSystemObject")

' vbsが配置されているフォルダ
Set CurrentFolder = FSO.GetFile(WScript.ScriptFullName).ParentFolder

' フォルダ内のファイルについて
For Each ObjFile In CurrentFolder.Files
    ' 拡張子を含む名前
    FullName=objFile.Name
        ' 拡張子
        extention=FSO.GetExtensionName(FullName)
        ' ファイル名
        FileName=FSO.GetBaseName(FullName)
        ' 拡張子がエクセルなら
        if extention="xls" or extention="xlsx" or extention="xlsm" Then
            ' 一時ファイルでなければ
            if Instr(FileName,"~$") = 0 Then
                ' エクセルを開く
                set Book = ExApp.workbooks.open(currentFolder & "/" & FullName)
                ' pdfへ変換
                Call Book.ExportAsFixedFormat(0,currentFolder & "/" & FileName)
                ' エクセルを終了
                ExApp.Quit
            End if
        End if 
Next
         
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?