Reputation: 1
I have a code I ran before on a temporary computer and ran perfectly but it seems I can't get it to run on this machine even if I reference suggested by the author
I get
Compile error Argument not optional
on Sub kl()
Sub kl()
Dim ie As InternetExplorer
Dim htlm As HTMLDocument
Dim link As Object
Dim links As Object
Dim erow As Long
Application.ScreenUpdating = False
Set ie = New InternetExplorer
ie.Visible = False
ie.navigate = "http://www.google.com"
Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "loading website"
DoEvents
Loop
Set Html = ie.document
Set links = Html.getElementsByTagName("a")
For Each link In links
erow = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = link
Cells(erow, 1).Columns.AutoFit
Next
Set.ie = Nothing
Application.StatusBar = ""
Application.screenupdate = True
End Sub
Any help on why it's causing error? Ive referenced MSXML, ActiveX Library, MSHTML and MS Internet Controls
I get error for ie.navigate = "http://www.google.com"
Working code :
Sub kl()
Dim ie As Object
Dim htlm As HTMLDocument
Dim link As Object
Dim links As Object
Dim erow As Long
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "http://www.google.com"
Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "loading website"
DoEvents
Loop
Set HTML = ie.document
Set links = HTML.getElementsByTagName("a")
For Each link In links
erow = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = link
Cells(erow, 1).Columns.AutoFit
Next
Set ie = Nothing
Application.StatusBar = ""
End Sub
Upvotes: 0
Views: 502
Reputation: 23283
I believe the error is in how you're creating and calling the Internet Explorer application.
Try this instead:
...
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "http://www.google.com" ' This seems to be the main thing, don't use `=`
...
Upvotes: 1