如何使用Excel宏将多个网页另存为pdf文件或屏幕截图? [英] How to save multiple web pages as pdf files or screenshot using excel macro?
本文介绍了如何使用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
推荐答案
查看全文