Home Compile error Argument not optional
Reply: 1

Compile error Argument not optional

Fitbit
1#
Fitbit Published in 2017-12-07 21:38:26Z

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
BruceWayne
2#
BruceWayne Reply to 2017-12-08 00:23:14Z

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 `=`
...
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299477 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO