How to fill a text field in internet explorer using VBA?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • loudey
    New Member
    • Mar 2010
    • 20

    How to fill a text field in internet explorer using VBA?

    I have a VBA program that automates an internet explorer process the whole code works except one piece.

    when I try using this code,

    Code:
    Dim IEapp As Object
      Dim IEdoc As Object
    Set IEapp = New InternetExplorer
    IEdoc.all("ctl00$ContentPlaceHolder1$uxQuantity").Value = 4
    I recieve an error that says "Run-time error '91': Object variable or With block variable not set"

    I think there is something I'm not seeing with the site source because I use a similar code for a different website and it works.

    I have attached the site source to this email and if someone can look at it and let me know whay am I missing I would highly appreciate it.

    Thanks
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You never assign the IEDoc variable. Right now it's nothing.

    Comment

    • loudey
      New Member
      • Mar 2010
      • 20

      #3
      thanks for your reply, oh sorry I missed up while copying the code

      Code:
      Dim IEapp As Object 
      Dim IEdoc As Object 
      Set IEapp = New InternetExplorer
      Set IEdoc = IEapp.document
      IEdoc.all("ctl00$ContentPlaceHolder1$uxQuantity").Value = 4
      I still have the same issue though, even with the IEDoc variable assigned
      thanks

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You've instantiated an internet explorer object but it's not actually on a page. It's either on a blank page or on whatever the homepage is at. If it's at the homepage, then it's likely the page hasn't finished loading.

        Comment

        • loudey
          New Member
          • Mar 2010
          • 20

          #5
          thanks for the reply and sorry I sent you a private message even though you had already replied but for some odd reason when I checked this post earlier it didn't show your reply.

          anyway I have been trying to avoid bothering you with the whole code so I have been just copying the part with the problem but that seemed that it have caused more problem than helped. so here is the full code.

          Code:
          Sub FixQtyMisMatch()
          
          Sheets("Sheet1").Select
          
          
          
            Dim IEapp As Object
            Dim IEdoc As Object
            Dim SearchText As String
            Dim URL As String
            Dim ElementCol As MSHTML.IHTMLElementCollection
            Dim Link As MSHTML.HTMLAnchorElement
            Dim i As Integer
            Dim EnterKey As String
              Set IEapp = New InternetExplorer
          
          
          i = 3
          
              
              'Define Quote Number
              QuoteNo = Cells(i, 29).Value
              
              
              ' Launch Internet Explorer and go to the site
              URL = "https://ccp.abb.com/Ccp/SearchTender.aspx"
              
          
              
                With IEapp
                  .Visible = True
                  .navigate URL
                End With
                      ' Wait till the page is loaded
                           While IEapp.Busy
                               DoEvents
                           Wend
                      ' Time delay for 5 seconds
                      Dim dclock As Double
                      dclock = Timer
                       While Timer < dclock + 5
                           DoEvents
                       Wend
              
          
              
              ' Inserts item number
                  Set IEdoc = IEapp.document
                  IEdoc.all("ctl00$ContentPlaceHolderMain$uxId").Value = QuoteNo
          
                    
               ' Clicks the search button
                 IEdoc.all("ctl00$ContentPlaceHolderMain$uxSearchButton").Click
                    ' Wait till the page is loaded
                           While IEapp.Busy
                               DoEvents
                           Wend
                   
             ' Clicks item link on search page
              Set ElementCol = IEapp.document.getElementsByTagName("a")
          
              For Each Link In ElementCol
               If Link.innerHTML = QuoteNo Then
                      Link.Click
                   Exit For
                  End If
              Next Link
                      ' Wait till the page is loaded
                           While IEapp.Busy
                               DoEvents
                           Wend
              
                         ' Clicks item link on search page
              Set ElementCol = IEapp.document.getElementsByTagName("a")
          
              For Each Link In ElementCol
               If Link.innerHTML = Cells(i, 27).Value Then
                      Link.Click
                   Exit For
                  End If
              Next Link
                      ' Wait till the page is loaded
                           While IEapp.Busy
                               DoEvents
                           Wend
                      
                      ' Insert Correct Quantity
              'EnterKey = "{enter}"
              IEdoc.all("ctl00$ContentPlaceHolder1$uxQuantity").Value = 4
              'IEdoc.all("ctl00_ContentPlaceHolder1_uxQuantity").Select
              'SendKeys EnterKey, True
             
                          ' Time delay for 1 seconds
                      dclock = Timer
                       While Timer < dclock + 1
                           DoEvents
                       Wend
                  
                  ' Clicks the Save FTC button
               ' IEdoc.all("ctl00$ContentPlaceHolderMain$uxFtc$uxSaveFtc").Click
                     'Wait till the page is loaded
                          While IEapp.Busy
                               DoEvents
                         Wend
           
              
             
               End Sub

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Can you post the source HTML of that page?

            Comment

            • loudey
              New Member
              • Mar 2010
              • 20

              #7
              Sorry didn't have access to my work computer over the weekend. Anyway please find the source HTML attached. let me know if you can't open it. (Couldn't attach HTML so i had to zip the file)
              Attached Files

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                I don't see a control with the identified as ctl00$ContentPl aceHolder1$uxQu antity in the source.

                Comment

                • loudey
                  New Member
                  • Mar 2010
                  • 20

                  #9
                  I don't think you can see the whole webpage in the HTML file, however if you click (CTRL-F) in the "site source.txt" and paste "ctl00$ContentP laceHolder1$uxQ uantity" you will find that under "Input Name" and that is where I want to fill in the text box. I have also included a jpeg of what the site looks like if this helps any.
                  Attached Files

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    Is it in a frame? Because you'll need to use
                    Code:
                    IEdoc.all("frameID").all("elementID")

                    Comment

                    • loudey
                      New Member
                      • Mar 2010
                      • 20

                      #11
                      that is a very good peice of information. to tell you the truth I'm not sure if it is in a frame or not (I don't know anything about java) but my best guess would be that it is since if you look at my initial code and you look at line 49 it is done the same way and it works.

                      Now how can I find the frame ID within the source of the site. I have been looking at the text file but I can't find anything. what should I be looking for.

                      Thanks

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        I only see one frame. Well, an iframe anyways.

                        <iframe id="ctl00_Conte ntPlaceHolderMa in_uxFrame" width="100%" height="100%" frameborder="0" src

                        Comment

                        • loudey
                          New Member
                          • Mar 2010
                          • 20

                          #13
                          just wondering how did you find this iframe. I didn't read through the whole text file ofcourse but I tried CTRL-F in the text file and can not find anything that says "iframe".

                          Comment

                          • Rabbit
                            Recognized Expert MVP
                            • Jan 2007
                            • 12517

                            #14
                            I did it the same way you did.

                            Comment

                            • loudey
                              New Member
                              • Mar 2010
                              • 20

                              #15
                              Thanks a lot I really appreciate all the time you have put into this and all the help you gave me. but it doesn't seem like I'm going to be able to get it done so I will just give up on it. thanks again

                              Comment

                              Working...