无需对话框Excel VBA即可将网页打印为pdf

时间:2021-05-13 14:24:18

标签: vba pdf web-scraping

我正在尝试使用 VBA 将网页下载为 pdf。我已经尝试了以下方法,它提示我选择要下载的文件夹和文件名。

有什么方法可以让我事先选择文件夹并自动保存网页而无需任何提示/对话框?

Sub printpdf()
URL = "https://www.londonstockexchange.com/news-article/CTEC/q1-trading-update/14956551"
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate (URL)
IE.StatusBar = False
IE.Toolbar = True
IE.Visible = True
IE.resizable = True
IE.AddressBar = False
    
TimeOutWebQuery = 5
TimeOutTime = DateAdd("s", TimeOutWebQuery, Now)
Do Until IE.readyState = 4
    DoEvents
    If Now > TimeOutTime Then
        IE.stop
        GoTo ErrorTimeOut
    End If
Loop

IE.ExecWB 6, 2
Application.Wait (Now + TimeValue("0:00:03"))

ErrorTimeOut:

Set IE = Nothing
End Sub

0 个答案:

没有答案
相关问题