VBA Excel,显示PDF格式

时间:2022-11-19 22:30:01

I am Running Excel 2016, and am not sure if I'm having a simple compatibility issue or what, hopefully someone can help me find a fix or suggest an alternative...

我正在运行Excel 2016,我不确定我是否有一个简单的兼容性问题,或者什么,希望有人能帮我找到解决方案或者建议一个替代方案……

In short, I am trying to display a PDF, embedded in a UserForm in Excel.

简而言之,我正在尝试显示一个PDF,嵌入到Excel中的UserForm中。

I have a UserForm, say UserForm1.

我有一个UserForm,比如UserForm1。

I have enabled the following extra references :

我已启用以下额外的参考资料:

Microsoft Visual Basic for Applications Extensibility 5.3

Microsoft Visual Basic应用程序可扩展性5.3。

Adobe Acrobat Browser Control Type Library 1.0

adobeacrobatbrowser控件类型库1.0。

This allows me to add the Adobe PDF Reader as an "Additional Control"

这允许我将adobereader添加为“附加控件”

VBA Excel,显示PDF格式

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 programatically and in design view) it gives me an error

控件显示为一个已孵化的框图标(左下角),我不确定它是否打算这样做。然后,如果我试图将其中一个对象添加到UserForm1(在编程和设计视图中),它会给我一个错误

Element not found

未找到元素

For reference, the relevant lines of VBA I was using were:

作为参考,我使用的VBA的相关行是:

Dim PDFviewer As AcroPDF
Set PDFviewer = PDForm.Frame1.Controls.Add("AcroPDF.PDF.1")

Which I took from this Adobe forums thread: https://forums.adobe.com/thread/1065554

我从这个Adobe论坛中获取的:https://forums.adobe.com/thread/1065554

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控件可能不再受支持。如果是这样的话,还有其他方法可以实现我想要的吗?

Thanks

谢谢

1 个解决方案

#1


7  

As an alternative to using the AcroPDF, try using the WebBrowser Object.

作为使用AcroPDF的另一种选择,可以尝试使用WebBrowser对象。

It requires including the additional control

它需要包含额外的控件

Microsoft Web Browser

微软的浏览器

Add a WeBrowser on the UserForm named WebBrowser1

在名为WebBrowser1的UserForm上添加一个WeBrowser

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

You can just .Navigate to the PDF directly, but, to quote my comment:

你可以直接导航到PDF,但是,引用我的评论:

"It's safer to use the html part, depending on the machine settings, sometimes direct navigation will initiate download instead of display."

“使用html部分更安全,这取决于机器的设置,有时直接导航会启动下载而不是显示。”

#1


7  

As an alternative to using the AcroPDF, try using the WebBrowser Object.

作为使用AcroPDF的另一种选择,可以尝试使用WebBrowser对象。

It requires including the additional control

它需要包含额外的控件

Microsoft Web Browser

微软的浏览器

Add a WeBrowser on the UserForm named WebBrowser1

在名为WebBrowser1的UserForm上添加一个WeBrowser

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

You can just .Navigate to the PDF directly, but, to quote my comment:

你可以直接导航到PDF,但是,引用我的评论:

"It's safer to use the html part, depending on the machine settings, sometimes direct navigation will initiate download instead of display."

“使用html部分更安全,这取决于机器的设置,有时直接导航会启动下载而不是显示。”