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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Sumner
Posts: 1
Joined: 2017-06-09T16:15:39-07:00
Authentication code: 1151

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply