VBA internet

PGD15

Board Regular
Joined
Aug 5, 2016
Messages
137
Hi!

I got a question with VBA (bit of a novice)

I've written the following code:
Code:
Sub test()    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    With IE
        .Visible = True
        .navigate ("secure website")
        While .Busy Or .readyState <> 4: DoEvents: Wend
    .Document.getElementById("User name").Focus
    .Document.getElementById("User name").Value = "my login"
    .Document.getElementById("Password").Focus
    .Document.getElementById("Password").Value = "My Pword"
    
    .Document.all("Login").Click
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Debug.Print .LocationURL
    End With
End Sub

however i don't the .document bit and how to update this to log myself onto the website. 77

Can someone please explain this too me :)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Someone can feel free to correct me but as far as I'm aware the internetexplorer.document object represents any web page loaded on the browser and provides an interface in which you can access data or manipulate things (like entering in a login or password). Essentially its the webpage with all the html, css and javascript behind it.
 
Upvote 0
Thanks Barry I thought as much, though im trying to do it for the following website where i believe the HTML information for the fields is called "username" and "password" when i try to use that combined with my login details no values are typed/entered by the macro.

I'm sure i've probably messed up somewhere but I dunno where as I rarely if ever use VBA im more or a formula sort of person lol

http://cwnet.clearwater.eu.com/
 
Upvote 0
looking at the page source, there arent any "id"'s. So can you try change the "getelementbyid" to getelementsbyname and see if that works?

im gonna try run it now also, i wont be able to login but ill see if things are being entered
 
Upvote 0
looking at the page source, there arent any "id"'s. So can you try change the "getelementbyid" to getelementsbyname and see if that works?

im gonna try run it now also, i wont be able to login but ill see if things are being entered

Upon changing the code i get the 'run-time error '438'' I believe there is something wrong with the 'object' but i don't really get what an object in VBA is so i probably made a typooo :(
 
Upvote 0
can you try the below?

Code:
Sub test()




Dim IE As Object
   Dim objElement As Object
    Dim objCollection As Object
    
    Set IE = CreateObject("InternetExplorer.application")
    With IE
        .Visible = True
        .Navigate ("http://cwnet.clearwater.eu.com/")
        While .Busy Or .ReadyState <> 4: DoEvents: Wend
    '.Document.getElementsbyname("User name").Focus
    .Document.getElementsbyname("username")(0).Value = "my login"
    .Document.getElementsbyname("password")(0).Value = "My Pword"
    
 Set objCollection = IE.Document.getElementsByTagName("input")
 
    i = 0
    While i < objCollection.Length
               If objCollection(i).Type = "submit" And _
               objCollection(i).Name = "" Then
 
                ' "Search" button is found
                Set objElement = objCollection(i)
 
    
        End If
        i = i + 1
    Wend
  
  
  
  
  objElement.Click
        While .Busy Or .ReadyState <> 4: DoEvents: Wend
        Debug.Print .LocationURL
    End With
End Sub
 
Upvote 0
<3 this works!!

sorry to be a pain 1 further question, upon logging in I need to click on several hyper links/tabs to get to where i want to go how would i go about adding this into the string?

edit:

2 questions* :) how do i maximise the pop up window? I know its something like object. visule maximise or something like this but actually compatible with vba lol
 
Last edited:
Upvote 0
good news. It's hard for me to say as I cant see the source code. If you look at the source code there are (i think) 4 types where you can access. they are:IE.document.getelementbyid("ID") 'Find by ID
IE.document.getelementsbytagname("ID")= "value" 'Find by tag
IE.document.getelementsbyclassname("ID") 'Find by class
IE.document.getelementsbyname("ID") 'Find by name

try match up whether there are id's or names you need to find. If you could copy the source code, paste it into a doc and share the document that would help (as long as thats not breaking any rules)
 
Upvote 0
good news. It's hard for me to say as I cant see the source code. If you look at the source code there are (i think) 4 types where you can access. they are:IE.document.getelementbyid("ID") 'Find by ID
IE.document.getelementsbytagname("ID")= "value" 'Find by tag
IE.document.getelementsbyclassname("ID") 'Find by class
IE.document.getelementsbyname("ID") 'Find by name

try match up whether there are id's or names you need to find. If you could copy the source code, paste it into a doc and share the document that would help (as long as thats not breaking any rules)


had a look at the code prettttyyy confused lol. Some are values I am certain of that however there are others which say href which i dunno what they are. it would be best to show you the code but I don't know how to share this (i will need to remove a couple of lines for confidential reasons, but they are not important in regards to what i want to do)


edit:
I think all are values think i was looking at the wrong bit of the code :')
there is a value such as "Value1" with an action "hhtp:/weblinkFORvalue1"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top