Login to webpage.

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Login to webpage.

Post by adam »

Hi anyone,

I'm using the following code to login to a web page.

Code: Select all

Sub login()

    Const Url$ = "https://abc.com/"

    Dim UserName As String, Password As String, LoginData As Worksheet
    Set LoginData = ThisWorkbook.Worksheets("Sheet3")
    UserName = LoginData.Cells(1, "B").Value
    Password = LoginData.Cells(2, "B").Value

    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .navigate Url
        ieBusy ie
        .Visible = True

        Dim oLogin As Object, oPassword As Object
        Set oLogin = .Document.getElementsByName("id")(0)
        Set oPassword = .Document.getElementsByName("password")(0)

        oLogin.Value = UserName
        oPassword.Value = Password
        .Document.forms(0).submit

    End With

End Sub
Sub ieBusy(ie As Object)
    Do While ie.Busy Or ie.readyState < 4
        DoEvents
    Loop
End Sub
The code does login me into the page. But Each time I run the code I get the runtime error91;
Object variable or with block variable not set highlighting the line oLogin.Value = UserName

How can I overcome this? any help on this would be kindly appreciated. Thanks in advance.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Login to webpage.

Post by HansV »

Not sure you'll find help here. I. for one, have no idea - sorry!
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Login to webpage.

Post by adam »

Thanks for the reply.

I don't get the error when I run the code for the first time. But If I close the explorer without logging out and then again run the code I get the error.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Login to webpage.

Post by HansV »

Perhaps .Document.getElementsByName("id")(0) is not available anymore after logging in?

(Just guessing, I don't know anything about this)
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Login to webpage.

Post by adam »

Thanks for the reply Hans.
Best Regards,
Adam

BilasTasol
NewLounger
Posts: 24
Joined: 09 Feb 2010, 17:25
Location: Rhondda Cynon Taff, S. Wales

Re: Login to webpage.

Post by BilasTasol »

Have you tried Selenium? Wise Owl Training has a playlist at https://www.youtube.com/watch?v=FoxWcvZzYVk . It allows you to access and manipulate websites through VBA using a variety of browsers.

Tony.
Regards,

Tony.

http://www.sylviahugheswilliams.com" onclick="window.open(this.href);return false;

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Login to webpage.

Post by ChrisGreaves »

BilasTasol wrote:
04 Aug 2021, 11:52
Have you tried Selenium? Wise Owl Training has a playlist at https://www.youtube.com/watch?v=FoxWcvZzYVk . It allows you to access and manipulate websites through VBA using a variety of browsers.

Tony., thank you for this link to Wise Owl. I followed the tutorial and got as far as "GET"ting a couple of web pages; a miracle for me.

I elected to follow the tutorial as exactly as I could to get started, and am now heading into the deep end of the pool.

Chrome insisted on upgrading to v94, although I did see something along the way about inhibiting updates. Nonetheless, here I am in Excel2003/VBA and Chrome v94 with gotten web pages.

Thanks again :thankyou:
Chris
An expensive day out: Wallet and Grimace

User avatar
BobH
UraniumLounger
Posts: 9211
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Login to webpage.

Post by BobH »

:groovin: Glad to see you fared well during the blow! :groovin: :
Bob's yer Uncle
(1/2)(1+√5)
Intel Core i5, 3570K, 3.40 GHz, 16 GB RAM, ECS Z77 H2-A3 Mobo, Windows 10 >HPE 64-bit, MS Office 2016

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Login to webpage.

Post by ChrisGreaves »

BobH wrote:
16 Oct 2021, 19:15
:groovin: Glad to see you fared well during the blow! :groovin: :
Thanks Bob.
Although we are now into our third week of string winds with nary a ceasefire. 92 & 98 Km/h the past two days, 111,110 a week ago. From the North, of course. Losing my newly-weighted chimney cap is a blow.

If you hear of anyone in Temple Tx in need of a selenium guru ... :cheers: :chocciebar:
Cheers
Chris
An expensive day out: Wallet and Grimace