用 VBA 打开 PDF 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43910271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open PDF file with VBA
提问by Cornelis
I'd like to open a PDF file using an Excel VBA macro.
我想使用 Excel VBA 宏打开 PDF 文件。
I have a list of names in the excel file. As soon as the commandbutton "Open PDF" is pressed i would like the macro to open a pdf file from a certain location.
我在 excel 文件中有一个名称列表。一旦按下命令按钮“打开 PDF”,我希望宏从某个位置打开 pdf 文件。
filename corrosponds with activecell.value
文件名与 activecell.value 对应
thanks in advance
提前致谢
Sub Knop1_Klikken()
Dim a As String
Dim myShell As Object
a = ActiveCell.Value
Set myShell = CreateObject("WScript.Shell")
myShell.Run "Z:\simbeton - Solidworks\bp - betonplaten\bp07 - simvlak ZH Sport\PDF\" & "a" & ".pdf"
End Sub
The error: (my MS is in dutch):
错误:(我的 MS 是荷兰语):
Fout -2147024894 (80070002) tijden uitvoering: Methode Run van object IWshSHell3 is mislukt
Fout -2147024894 (80070002) tijden uitvoering: Methode Run van object IWshSHell3 is mislukt
Translated:Error -2147024894 (80070002) during execution: Methode Run of object IWshSHell3 has failed.
翻译:执行过程中出现错误 -2147024894 (80070002):对象 IWshSHell3 的 Methode 运行失败。
回答by Koby Douek
You can simply use WScript.Shell
like this:
你可以简单地WScript.Shell
像这样使用:
a = ActiveCell.Value
Dim myShell As Object
Set myShell = CreateObject("WScript.Shell")
myShell.Run "C:\" & a & ".pdf"
回答by Dave
Have you find out how it's done yet? If not, here 's the solution:
你知道它是如何完成的吗?如果没有,这是解决方案:
myShell.Run chr(34) & "C:\" & a & ".pdf" & chr(34)
chr(34) is a "
chr(34) 是一个“
The difference is : your command sends C:\JouBetonInfo.pdfas an argument whereas my command sends "C:\JouBetonInfo.pdf"as an argument. Note the quotes that I send along. It works for me (Excel 2007).
不同之处在于:您的命令发送C:\JouBetonInfo.pdf作为参数,而我的命令发送"C:\JouBetonInfo.pdf"作为参数。请注意我发送的报价。它对我有用(Excel 2007)。