在Excel VBA UserForm中显示PDF
我正在运行Excel 2016,如果以下是兼容性问题,则可能与之相关...
I am running Excel 2016, which may be relevant if the below is a compatibility issue...
简而言之,我试图显示嵌入在Excel的用户窗体中的PDF.
我有一个用户窗体,例如UserForm1
.
I have a UserForm, say UserForm1
.
我启用了以下额外参考:
I have enabled the following extra references:
- 用于应用程序扩展性5.3的Microsoft Visual Basic
- Adobe Acrobat浏览器控件类型库1.0
这使我可以将Adobe PDF Reader
添加为其他控件"
This allows me to add the Adobe PDF Reader
as an "Additional Control"
该控件显示为带阴影的框图标(左下),我不确定它的意图.然后,如果我尝试将这些对象之一添加到UserForm1
(以编程方式和在设计视图中),则会给我一个错误
The control appears as a hatched box icon (bottom left), which I'm not sure it's meant to. Then if I try to add one of these objects to UserForm1
(both programmatically and in design view) it gives me an error
找不到元素
Element not found
作为参考,我使用的VBA的相关行是:
For reference, the relevant lines of VBA I was using were:
Dim PDFviewer As AcroPDF
Set PDFviewer = PDForm.Frame1.Controls.Add("AcroPDF.PDF.1")
我从这个Adobe论坛线程中获取了以下信息: https://forums.adobe.com/thread/1065554
Which I took from this Adobe forums thread: https://forums.adobe.com/thread/1065554
在线资源表明,可能是不再支持AcroPDF控件.如果是这样,还有另一种方法可以实现我想要的吗?
Resources online suggest it might be that the AcroPDF control is no longer supported. If so, is there another way to achieve what I want?
作为使用AcroPDF
的替代方法,请尝试使用WebBrowser
对象.
As an alternative to using the AcroPDF
, try using the WebBrowser
Object.
它需要包括其他控件
Microsoft Web Browser
在名为WebBrowser1
Private Sub UserForm_Click()
Me.WebBrowser1.Navigate "about:blank"
Me.WebBrowser1.Document.write "<HTML><Body><embed src=""C:\temp\SO_Answers\test.pdf"" width=""100%"" height=""100%"" /></Body></HTML>"
End Sub
您可以直接.Navigate
直接打开PDF,但是要引用我的评论:
You can just .Navigate
to the PDF directly, but, to quote my comment:
使用html部分更安全,具体取决于机器设置,有时直接导航会启动下载而不是显示."