创建批处理文件

发布于 2024-09-09 11:02:49 字数 538 浏览 4 评论 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2024-09-16 11:02:49

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

@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 准确编写它,所以也许其他人可以帮助你。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文