I am trying to save HTML as PDF using VBA.
I don't know how to check what is the default printer change it to Microsoft Print to PDF and then back to the old printer.
Below is my code: I search something on Google, then enter the links on the first Google Search page and then I would like to print searches to PDF.
Sub Main()
Dim search As String
Dim save_path As String
Dim number As Integer
number = 5
save_path = ""
Dim query As String
query = InputBox("Enter here your search", "Google Search")
search = query
search = Replace(search, " ", "+")
PDFFolderSelection save_path, search
Debug.Print save_path, search
Google_Search search, save_path, number
End Sub
Sub Google_Search(search As String, save_path As String, number As Integer)
Dim IE As InternetExplorerMedium
Set IE = CreateObject("InternetExplorer.Application")
Dim HTMLDoc As MSHTML.HTMLDocument
IE.Navigate "http://google.com/#q=" & search
IE.Visible = True
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Dim RCS As MSHTML.IHTMLElementCollection
Dim RC As MSHTML.IHTMLElement
Set RCS = HTMLDoc.getElementsByClassName("rc")
Dim Atags As MSHTML.IHTMLElementCollection
Dim Atag As MSHTML.IHTMLElement
Dim URLs As New Collection
Dim URL As MSHTML.IHTMLElement
Set URLs = Nothing
For Each RC In RCS
Dim RS As MSHTML.IHTMLElementCollection
Dim R As MSHTML.IHTMLElement
Set RS = RC.getElementsByClassName("r")
For Each R In RS
Set Atags = R.getElementsByTagName("a")
For Each Atag In Atags
URLs.Add Atag
Next Atag
Next R
Next RC
For Each URL In URLs
Dim IEs As InternetExplorerMedium
Set IEs = CreateObject("InternetExplorer.Application")
str_text = Replace(URL.getAttribute("href"), "", "")
str_text = Replace(str_text, "", "")
'Debug.Print str_text
IEs.Navigate str_text
IEs.Visible = True
Do While IEs.ReadyState <> READYSTATE_COMPLETE Or IEs.Busy
Loop
IEs.Quit
Set IEs = Nothing
Next URL
IE.Quit
Set IE = Nothing
End Sub