views:

39

answers:

1

I'm trying to create a batch file that will convert an Excel file to a PDF. Is there something wrong with my command line because it doesn't seem to work:

Dim i As Double
Dim sBatchFile As String
ActiveWorkbook.Save
sBatchFile = "C:\test.bat"
Open sBatchFile For Output As #1
    Print #1, "@ECHO OFF"
    Print #1, "ECHO Converting Excel Files to PDF, Please wait..."
    Print #1, "batchpdf C:\Documents and Settings\Andrew_G\My Documents\Office Docs\Schedule.xls C:\Documents and Settings\Andrew_G\My Documents\Office Docs\TEST1234.pdf"
    Close #1

    i = Shell(sBatchFile, vbMaximizedFocus)
End Sub
+3  A: 

If this is the actual content of your batch file:

@ECHO OFF
ECHO Converting Excel Files to PDF, Please wait...
batchpdf C:\Documents and Settings\Andrew_G\My Documents\Office Docs\Schedule.xls C:\Documents and Settings\Andrew_G\My Documents\Office Docs\TEST1234.pdf

then you need to quote any file pathes with "" like this:

batchpdf "C:\Documents and Settings\Andrew_G\My Documents\Office Docs\Schedule.xls" "C:\Documents and Settings\Andrew_G\My Documents\Office Docs\TEST1234.pdf"

But I don't know how to exactly write it with VBA, so maybe someone else can help you with that.

Frank Bollack
Yeah, that fixed my problem in CMD but not in VBA.
BioXhazard
I just used double quotes and it worked. Thanks
BioXhazard