2010-07-13 247 views
0

我正在嘗試創建一個將Excel文件轉換爲PDF的批處理文件。是不是有什麼毛病我的命令行,因爲它似乎不工作:創建批處理文件

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

如果這是您的批處理文件的實際內容:

@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 

,那麼你需要引用的任何文件pathes與""這樣的:

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" 

但我不知道如何準確使用VBA編寫,所以也許別人可以幫你。

+0

是的,這解決了我的問題在CMD但不是在VBA。 – BioXhazard 2010-07-13 14:44:03

+0

我只用雙引號,它工作。謝謝 – BioXhazard 2010-07-13 15:23:30