Results 1 to 9 of 9

Thread: [VBA] Getting information from Website

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    5

    [VBA] Getting information from Website

    Hello to everyone!

    I'm trying to put information in a website with MS Excel VBA.
    The code of the page that I'm accessing is attached.
    I'm trying to access through VBA the information "frota" that is in a form1 format.

    I've already tried the commands:
    ie.document.getelementbyid (and also name, tagname, etc) but without success.

    I'm fairly new in VBA, so excuse me for my low level of knowledge in it

    Cheers
    Attached Images Attached Images

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [VBA] Getting information from Website

    i fail to understand what you are trying to do

    are you trying to read the value from the html page? change what is displayed in your browser? or change the html file on the server?

    post what code you have tried so far,

    there is an input element named Frota, but that is not its ID, you could try
    Code:
    ie.document.all("Frota").value = "xxx"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    5

    Re: [VBA] Getting information from Website

    Quote Originally Posted by westconn1 View Post
    i fail to understand what you are trying to do

    there is an input element named Frota, but that is not its ID, you could try
    Code:
    ie.document.all("Frota").value = "xxx"
    thanks for the answer!
    so.. the attached code is from one page in which i'm trying to put a value in the field 'frota' through Excel VBA (document.form1.frota.value)
    it's a website that u have to access with login and all that stuff... and i've managed to VBA it up to this point haha

    yep, this field does not have an ID, it has just the name "frota" and i've tried a bunch of commands to insert a value, like:

    - ie.document.all("frota").value = "x"
    - ie.document.form.item
    - ie.document.getelementbyname (as well as tagname, id)

    and a lot more but without success

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [VBA] Getting information from Website

    so.. the attached code is from
    i meant your vba code

    i tested on my machine, it worked fine, so you must be doing something wrong, but as you have not posted the vba code impossible to tell
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    5

    Re: [VBA] Getting information from Website

    Quote Originally Posted by westconn1 View Post
    i meant your vba code
    sorry about that, but the code is at a file in the company's in which i work computer
    i'll get this code on tuesday and than i post it here
    thanks for your help!

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    5

    Re: [VBA] Getting information from Website

    Quote Originally Posted by westconn1 View Post
    i meant your vba code
    Hey! Sorry for the late, i had a lot of work to do during the week.
    This is the code vba that i used:

    Sub tela()
    Dim ie As InternetExplorer

    Dim frm

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://unilogvli/unilog/Index.asp?mode=logon"

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    %first page - login page
    %commands to insert login parameters
    ie.Document.getElementById("usuario").Value = ""
    ie.Document.getElementById("senha").Value = ""
    ie.Document.all("form1").submit
    Do While ie.Busy
    Loop

    %second page - 115 link value of a page that i have to access
    ie.Document.all("Link").Value = "115"
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
    SendKeys "{ENTER}", True %sendkey command used to access the 115 link
    SendKeys "{NUMLOCK}", True %after the sendkey used before numlock is turned off
    Do While ie.Busy
    Loop

    %in the third page which is the one that i'm having trouble
    %i have to access the field frota and put the value "00862"
    %and after that i have to simulate the "ENTER" another time
    %i thought in using the sendkey "{ENTER}" to do this
    %and i had tried it but without success
    %strangely it doesn't work like the previous page so i think
    %that i'll have to use smth like "ie.document.all("form1").submit" again

    %all the commands that i've used so far, without results for this third page:

    ' ie.Document.forms("form1").Document.all("frota").Value = "00862"

    'Set frm = ie.Document.forms("form1")
    ' Set frm.elements("frota").Value = "00862"
    ' frm.elements("frota").Value = "00862"

    ' ie.Document.forms.Item("form1").Document.all("frota").Value = "00862"

    ' ie.Document.forms.form1(0).Value = "88"

    ' ie.Document.all("frota").Value = "00862"

    ' ie.Document.all("frota").submit

    ' Application.Wait (Now + TimeValue("00:00:03"))

    ' ie.Document.all("form1.frota").Value = "00862"

    ' objIE.Document.all("form1.frota.value").Value = "00862"

    ' ie.Document.getElementById("frota").Value = "00862"

    %these are all the commands

    Set ie = Nothing
    End Sub
    I tried others commands but they didn't work again.
    Thks!

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [VBA] Getting information from Website

    i would try to test this for you, but i do not have access to the site

    i tested against the source code of the page, as you posted above, and worked correctly without error

    what version of windows and internet explorer are you using?
    Last edited by westconn1; Nov 13th, 2017 at 02:51 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    5

    Re: [VBA] Getting information from Website

    at the company we use windows 7, and i only have access to firefox and ie (i use ie to access the website and its version is pretty old. for the firefox i have no idea of the version)
    could it be this the problem? the broser version?

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [VBA] Getting information from Website

    could it be this the problem? the broser version?
    i doubt it, but i have recently had some problem like that, i can down load a file with firefox, but can not even connect to the site with internet explorer

    as you have internet explorer visible you should be able to see any such problem

    you may have a timing problem, that the web page has not loaded even though it is ready state complete, you could try an actual delay of 2 or 3 seconds to see if it makes any difference, unfortunately do while some_element is nothing no longer works in later versions, i had to stop using that loop

    beyond this, which i am only guessing, not much i can do without testing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width