Excel Webbrowser在用户表单中滚动

时间:2015-09-28 13:05:45

标签: excel-vba vba excel

我创建了一个userform并添加了一个webbrowser控件。我正在将PDF图像加载到userform上的webbrowser控件中。我想要做的是添加一个按钮来向下滚动webbrowser,这样我就可以看到pdf的下一页。

1 个答案:

答案 0 :(得分:1)

您可以将.Navigate#page=一起移至相关页面。以下是我们转到第2页的示例。

Dim FName As String

Private Sub UserForm_Initialize()
    '~~> Replace this with the relevant file name
    FName = "C:\Sample.pdf"

    WebBrowser1.Navigate "file:///" & FName
End Sub

Private Sub CommandButton1_Click()
    Dim PageNo As Long

    PageNo = 2

    '~~> I noticed that if I do not include
    '~~> this line then the next .Navigate doesn't work
    WebBrowser1.Navigate "About:Blank"
    Wait 1 '<~~ Wait for a second

    WebBrowser1.Navigate ("file:///" & FName & "#page=" & PageNo)
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub