如何使用Excel宏将多个网页另存为pdf文件或屏幕截图? [英] How to save multiple web pages as pdf files or screenshot using excel macro?

查看:61
本文介绍了如何使用Excel宏将多个网页另存为pdf文件或屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了下面的代码,但是它仅保存页面的HTML内容,并且最终排除了页面上的大多数重要内容.

I tried out the code below but its only saving the page's HTML content and ends up excluding most of the important content on the page.

如果有人可以帮助我将这些网页另存为pdf或png文件,那就太好了.

If anyone can help me on how to save these webpages as pdf or a png file it would be great.

Sub SaveWebpage()
    Dim objHTTP As Object, _
        objFSO As Object, _
        objFil As Object, _
        lngRow As Long, _
        strURL As String, _
        strPath As String, _
        strFilename As String
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'On the next line change the file path as desired.  Make sure the path ends with \
    strPath = "C:\Users\Pradyumna\Desktop\Save Webpages"
    For lngRow = 2 To Application.ActiveSheet.UsedRange.Rows.Count
        strFilename = strPath & lngRow & ".htm"
        strURL = Application.ActiveSheet.Cells(lngRow, 1).Value
        objHTTP.Open "GET", strURL, False
        objHTTP.send ""
        Set objFil = objFSO.CreateTextFile(strFilename)
        objFil.Write objHTTP.responseText
        objFil.Close
    Next
    Set objHTTP = Nothing
    Set objFSO = Nothing
    Set objFil = Nothing
    MsgBox "All done!"
End Sub

推荐答案

您可以简单地

您需要指定Chrome以及要保存的PDF文件的实际路径.请注意,您需要使用Chrome版本60或更高版本才能在Windows上运行代码.

You need to specify the actual path to your Chrome, and to the PDF file to be saved. Note, you need Chrome version 60 or higher to run the code on Windows.

这篇关于如何使用Excel宏将多个网页另存为pdf文件或屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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