473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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

when I try using this code,

Expand|Select|Wrap|Line Numbers
  1. Dim IEapp As Object
  2.   Dim IEdoc As Object
  3. Set IEapp = New InternetExplorer
  4. 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
File Type: txt site source.txt (25.8 KB, 900 views)
Feb 2 '11 #1
14 13640
Rabbit
12,516 Expert Mod 8TB
You never assign the IEDoc variable. Right now it's nothing.
Feb 2 '11 #2
loudey
20
thanks for your reply, oh sorry I missed up while copying the code

Expand|Select|Wrap|Line Numbers
  1. Dim IEapp As Object 
  2. Dim IEdoc As Object 
  3. Set IEapp = New InternetExplorer
  4. Set IEdoc = IEapp.document
  5. IEdoc.all("ctl00$ContentPlaceHolder1$uxQuantity").Value = 4
  6.  
I still have the same issue though, even with the IEDoc variable assigned
thanks
Feb 3 '11 #3
Rabbit
12,516 Expert Mod 8TB
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.
Feb 3 '11 #4
loudey
20
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.

Expand|Select|Wrap|Line Numbers
  1. Sub FixQtyMisMatch()
  2.  
  3. Sheets("Sheet1").Select
  4.  
  5.  
  6.  
  7.   Dim IEapp As Object
  8.   Dim IEdoc As Object
  9.   Dim SearchText As String
  10.   Dim URL As String
  11.   Dim ElementCol As MSHTML.IHTMLElementCollection
  12.   Dim Link As MSHTML.HTMLAnchorElement
  13.   Dim i As Integer
  14.   Dim EnterKey As String
  15.     Set IEapp = New InternetExplorer
  16.  
  17.  
  18. i = 3
  19.  
  20.  
  21.     'Define Quote Number
  22.     QuoteNo = Cells(i, 29).Value
  23.  
  24.  
  25.     ' Launch Internet Explorer and go to the site
  26.     URL = "https://ccp.abb.com/Ccp/SearchTender.aspx"
  27.  
  28.  
  29.  
  30.       With IEapp
  31.         .Visible = True
  32.         .navigate URL
  33.       End With
  34.             ' Wait till the page is loaded
  35.                  While IEapp.Busy
  36.                      DoEvents
  37.                  Wend
  38.             ' Time delay for 5 seconds
  39.             Dim dclock As Double
  40.             dclock = Timer
  41.              While Timer < dclock + 5
  42.                  DoEvents
  43.              Wend
  44.  
  45.  
  46.  
  47.     ' Inserts item number
  48.         Set IEdoc = IEapp.document
  49.         IEdoc.all("ctl00$ContentPlaceHolderMain$uxId").Value = QuoteNo
  50.  
  51.  
  52.      ' Clicks the search button
  53.        IEdoc.all("ctl00$ContentPlaceHolderMain$uxSearchButton").Click
  54.           ' Wait till the page is loaded
  55.                  While IEapp.Busy
  56.                      DoEvents
  57.                  Wend
  58.  
  59.    ' Clicks item link on search page
  60.     Set ElementCol = IEapp.document.getElementsByTagName("a")
  61.  
  62.     For Each Link In ElementCol
  63.      If Link.innerHTML = QuoteNo Then
  64.             Link.Click
  65.          Exit For
  66.         End If
  67.     Next Link
  68.             ' Wait till the page is loaded
  69.                  While IEapp.Busy
  70.                      DoEvents
  71.                  Wend
  72.  
  73.                ' Clicks item link on search page
  74.     Set ElementCol = IEapp.document.getElementsByTagName("a")
  75.  
  76.     For Each Link In ElementCol
  77.      If Link.innerHTML = Cells(i, 27).Value Then
  78.             Link.Click
  79.          Exit For
  80.         End If
  81.     Next Link
  82.             ' Wait till the page is loaded
  83.                  While IEapp.Busy
  84.                      DoEvents
  85.                  Wend
  86.  
  87.             ' Insert Correct Quantity
  88.     'EnterKey = "{enter}"
  89.     IEdoc.all("ctl00$ContentPlaceHolder1$uxQuantity").Value = 4
  90.     'IEdoc.all("ctl00_ContentPlaceHolder1_uxQuantity").Select
  91.     'SendKeys EnterKey, True
  92.  
  93.                 ' Time delay for 1 seconds
  94.             dclock = Timer
  95.              While Timer < dclock + 1
  96.                  DoEvents
  97.              Wend
  98.  
  99.         ' Clicks the Save FTC button
  100.      ' IEdoc.all("ctl00$ContentPlaceHolderMain$uxFtc$uxSaveFtc").Click
  101.            'Wait till the page is loaded
  102.                 While IEapp.Busy
  103.                      DoEvents
  104.                Wend
  105.  
  106.  
  107.  
  108.      End Sub
  109.  
  110.  
Feb 4 '11 #5
Rabbit
12,516 Expert Mod 8TB
Can you post the source HTML of that page?
Feb 4 '11 #6
loudey
20
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
File Type: zip Source.zip (5.2 KB, 283 views)
Feb 7 '11 #7
Rabbit
12,516 Expert Mod 8TB
I don't see a control with the identified as ctl00$ContentPlaceHolder1$uxQuantity in the source.
Feb 7 '11 #8
loudey
20
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$ContentPlaceHolder1$uxQuantity" 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 Images
File Type: jpg website.jpg (78.6 KB, 602 views)
Feb 7 '11 #9
Rabbit
12,516 Expert Mod 8TB
Is it in a frame? Because you'll need to use
Expand|Select|Wrap|Line Numbers
  1. IEdoc.all("frameID").all("elementID")
Feb 7 '11 #10
loudey
20
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
Feb 7 '11 #11
Rabbit
12,516 Expert Mod 8TB
I only see one frame. Well, an iframe anyways.

<iframe id="ctl00_ContentPlaceHolderMain_uxFrame" width="100%" height="100%" frameborder="0" src
Feb 7 '11 #12
loudey
20
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".
Feb 8 '11 #13
Rabbit
12,516 Expert Mod 8TB
I did it the same way you did.
Feb 8 '11 #14
loudey
20
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
Feb 8 '11 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ronen | last post by:
Hi, Does anyone experienced memory leak in Iexplore.exe when use treeview (MS IE Controls? I'm have tested this with a simple web page with a few tree nodes generated on the server. Then I...
2
by: Ofer Lavi | last post by:
Hi, I am trying to build an activeX that, if missing, will be downloaded and setup automatically on the client's browser (internet explorer). Using VB6, it was easy, using the <Object> tag,...
2
by: v.srikhar | last post by:
hi I had some problem .Ii had to open the ms word file in IE itself not outside using jsp or java can any one solve it out. thanks
1
by: Andy Chen | last post by:
Some web sites offer contents in multiple languanges, we can do it manully by click on IE Options - Internet options. My questions is how to change it by C# code. Thanks! Andy
11
by: Wendy | last post by:
Hello, I have a program that does the following: When a user clicks on a row in a VB.NET datagrid, it will open a web page in Internet Explorer (that corresponds to that item in the selected row...
0
by: pigeonrandle | last post by:
Hi, Has anyone tackled this before? I understand i might need to use the DOM, but cant work out how to get the handle of a 'child window' from it :(. The instance of Internet Explorer Server is...
0
by: jaggu | last post by:
HI All, I was making a demo were in i will set the uri path for the internet explorer using setURI function....along with this i also want to set the user name and password for the webpage...
0
by: gaurav2325 | last post by:
Hi, I would like to create a plugin for internet explorer to run my document. My document contains specific type of data, so that, I want whenever the user open that document (that is word...
0
by: nehacredo | last post by:
hi alll.. i wanna display a word file content in a browser..how can i do that..i hav done one coding in that i can display the contents...but with contents some symbols also coming... anyone pls...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.