使用Web浏览器控件访问vba显示本地PDF文件

时间:2016-04-04 10:34:02

标签: vba ms-access access-vba

在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

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

谢谢!

1 个答案:

答案 0 :(得分:2)

试试这个:

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

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