Page 1 of 1

vba script to batch convert a folder of tiff to one pdf

Posted: 2017-06-09T16:31:54-07:00
by Sumner
I have 10,000 folders, and need to batch convert all tiff files in each folder to one pdf file.
I listed the Source folder directory in the Column A of an Excel file, and list the pdf file name in Column B.
I want to use the VBA to go through each row, and batch convert each folder to one pdf.

I am able to use the following script to convert if the "path" is pointing to one tif file.(like c:\temp\test.tif) I couldn't figure out how to change the script to convert the entire folder to one pdf.

Code: Select all

Sub ConvertPdf()
Dim r As Integer
For r = 1 To 2
Dim Path As String
Dim pdfname As String
Path = ActiveSheet.Cells(r, 1).Value
pdfname = ActiveSheet.Cells(r, 2).Value

Set img = CreateObject("ImageMagickObject.MagickImage.1")
img.Convert Path, pdfname
Next r
End Sub

Re: vba script to batch convert a folder of tiff to one pdf

Posted: 2017-06-10T22:58:19-07:00
by snibgo
Sumner wrote:I couldn't figure out how to change the script to convert the entire folder to one pdf.
At the command line interface, the command would be something like:

Code: Select all

convert \mydir\subdir\*.tiff \outdir\out.pdf
Note the wildcard in the input filename. I don't use VBA and can't advise, but I suppose that's what you need to do.