I have a large number of forms that are all organized in MS Excel. These forms are updated fairly often and I need to download the new updates when this happens. Each row has it's own hyperlink associated to the pdf document online. Currently I have to click each link which opens the file in IE. From there I have to save each file individually to a local location. This process takes a considerable amount of time so I was hoping to automate it. Below is code I have found on this forum used for another application and tried to modify it to the best of my ability. FYI this is an embedded hyperlink.
When I go line by line and watch either strTEXT or strURL, it is pulling in the correct hyperlink.
example link: https://www.mysite.com/thunder.pdf
hopeful file saved: c:\thunder.pdf
Option Explicit
Sub Save()
Dim HL As Excel.Hyperlink
Dim ws As Excel.Worksheet
Dim strURL As String
Dim strText As String
Dim FSO As Object
Dim ts As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
Set ws = ActiveSheet
For Each HL In ws.Hyperlinks
strURL = HL.Address
ie.navigate strURL
Do Until ie.readystate = 4
DoEvents
Loop
strText = ie.document.body.innertext
Set ts = FSO.createTextfile("C:\" & HL.Name)
ts.Write strText
ts.Close
Next HL
End Sub
My program stops on the red line above with the following message.
Run-time erroe '438': Object doesn't support this property or method.
Am I on the right path?
Thanks
Josh
When I go line by line and watch either strTEXT or strURL, it is pulling in the correct hyperlink.
example link: https://www.mysite.com/thunder.pdf
hopeful file saved: c:\thunder.pdf
Option Explicit
Sub Save()
Dim HL As Excel.Hyperlink
Dim ws As Excel.Worksheet
Dim strURL As String
Dim strText As String
Dim FSO As Object
Dim ts As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
Set ws = ActiveSheet
For Each HL In ws.Hyperlinks
strURL = HL.Address
ie.navigate strURL
Do Until ie.readystate = 4
DoEvents
Loop
strText = ie.document.body.innertext
Set ts = FSO.createTextfile("C:\" & HL.Name)
ts.Write strText
ts.Close
Next HL
End Sub
My program stops on the red line above with the following message.
Run-time erroe '438': Object doesn't support this property or method.
Am I on the right path?
Thanks
Josh