代码之家  ›  专栏  ›  技术社区  ›  BioXhazard

创建批处理文件

  •  0
  • BioXhazard  · 技术社区  · 16 年前

    我正在尝试创建一个将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
    
    1 回复  |  直到 16 年前
        1
  •  3
  •   Frank Bollack    16 年前

    如果这是批处理文件的实际内容:

    @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
    

    然后你需要引用任何文件路径 "" 这样地:

    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来写它,所以也许其他人可以帮你。

    推荐文章