【问题标题】:Access vba display local PDF file using web browser control使用网络浏览器控制访问vba显示本地PDF文件
【发布时间】:2016-04-04 10:34:01
【问题描述】:

在 ms access 2013 中,我有一个用户表单 (frm_viewer),其中包含一个名为 wbContent 的 Web 浏览器控件。

我编写了以下代码来填充和显示本地 PDF 文件,但似乎无法使其正常运行。

我确实设法通过将控件的 Control Source 属性引用到同一表单上的文本框(即 Control Source -> Base URL -> Expression Builder -> =[MyTextbox])来使其工作,但我不想要要使用此方法,我更喜欢使用变量动态填充它。

Private Sub lblBrowse_Click()

'declare file dialog with late binding ->
Dim fDialog As Object, strPath As String
Set fDialog = Application.FileDialog(3) 'msoFilePicker

'set parameters ->
Me.wbContent.ControlSource = ""

    'initializing the file dialog ->
    With fDialog
        .AllowMultiSelect = False
        .Filters.Clear        '
        .title = "Please select a file..."

        'display the dialog box. If the .Show method returns True
        'the user picked a file. If the .Show method returns False
        'the user clicked Cancel.
        If .show = True Then
            strPath = .SelectedItems(1)
            Debug.Print "SELECTED_FILE: " & strPath

            'set source property to the string containing the full path ->
            Me.wbContent.ControlSource = strPath
            Me.wbContent.Requery
        Else

        End If
    End With

End Sub

有人可以看看我的代码并告诉我如何让它正常运行吗?

谢谢!

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    试试这个:

    Me.wbContent.ControlSource = "='" & strPath & "'"
    

    控制源需要是这样的字符串:='http://www.address.com'

    【讨论】:

    • 传奇!那行得通。看起来 web 控件源属性与 vba 表单中的其他典型表单控件有很大不同。至少可以说它很繁琐!再次感谢
    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    • 2018-04-10
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多