2010-07-13 178 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