在Excel VBA UserForm中显示PDF [英] Display PDF in Excel VBA UserForm

查看:559
本文介绍了在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
  • Adob​​e 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部分更安全,具体取决于机器设置,有时直接导航会启动下载而不是显示."

这篇关于在Excel VBA UserForm中显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆