Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > VBA Interaction with Internet Explorer


Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2004, 05:49 PM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Unhappy VBA Interaction with Internet Explorer


Hi everyone, I'm new to this site and I desperately need some help. I've been searching for over two days but haven't found the answer. What I need is to connect to the internet from excel (with VBA) and then insert information onto a website. To do this I have to sign into the website and then post the information.

Currently, I am able to login into the site but this is all I can do. I have never connected to the internet with VBA, but I have been able to put together the following code from other postings.

Sub test()

Dim ie As Object
dim login_name
dim password

login_name = "login"
password = "password"

Set ie = CreateObject("InternetExplorer.Application")

With ie
.MenuBar = 1
.Toolbar = 1
.StatusBar = 1
.Navigate "www.websitename.com"
.Visible = 1

End With

'wait a while until IE as finished to load
Do While ie.busy
Loop

DoEvents
Call SendKeys(login_name) 'This is the Login Name Box.
DoEvents
Call SendKeys("{tab}") 'I am tabbing to the password box.
DoEvents
Call SendKeys(password) 'Password Box
DoEvents
Call SendKeys("{tab}") ' Tab to the "login" button.
DoEvents
Call SendKeys("{enter}") 'Hit enter on the "login" button


At this point, I am having problems. The previous code took me to the next page but I am unable to use the tab feature on that page. By the way the reason that I have to use the tab is that the website is not listing the source code, so I do not know the names of the Input Boxes.

Here are a few questions.
1.) Is there anyway to use the sendkeys method with having to use the "DoEvents, Call SendKeys". I tried to use the ie.sendkeys but it does not work
2.) How do I determine when the second page has loaded. I tried to use the Do While ie.busy/Loop method from above but it doesn't work.
3.) Why am I not able to use the "Tab method on the second page."--I guess this is related to the second question.
4.) Is it possible to use the webbrowser control in excel (VBA), if so, can you show how to the webbrowser.

I know this is a long post but I would greatly appreciate any help Any help you can provide, I am pulling my hair out by the second.

Thanks
Reply With Quote
  #2  
Old 01-28-2004, 11:06 PM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #3  
Old 01-29-2004, 07:15 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

Thanks for the link but I had come accross this one earlier. It seems that I am unable to tab accross the data on the second page. I've tried to use the: While IE.busy/doevents/wend: command to wait until the second page loads and then use the tab function but it doesn't work. Any ideas?
Reply With Quote
  #4  
Old 01-29-2004, 07:35 AM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

It probably has to do with the way the second page is loading. It may be bouncing to another page, or loading soemthing such as flash which confuses the while.busy line. Can we see this page?

The first load assumes the cursor is located in the loginname box. If there is not a default, your tab is usually set to something higher than the address bar. try loading the page normaly, and hitting tab a bunch of times to see where your cursor ends up.

To tell if the page is loaded, you could pull the text on the screen, and compare it to a string of data that is last to load. when they match, wait another 1/2 or full second, then begin sending keys. I don't like the sendkey function unless there is no other way to accomplish the objective.
__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #5  
Old 01-29-2004, 08:39 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

Hi Evadman,

I have tabbed on the page (manually) and I am able to move along the page. However, when I run the program it tabs on the first page between login and password but it does not tab on the second page. I don't know why, maybe it doesn't think the second page has finished loading. Is there another method I can use to see if the page has finished loading. I noticed on Microsoft website the downloadcomplete and documentcomplete options but I do not see how it works

Also, do you know of another way that I can use the .sendkeys other than the DoEvents/SendKeys method. I noticed on the link that they used objShell.SendKeys "{TAB}". However, I am not familiar with the SHELL_OBJECT = "WScript.Shell" script.

As for using sendkeys, I hate doing it as well. I noticed that you are a Attachmate guru. Unfortunately, Attachmate (Extra) is the program that got me in the habbit of using sendkeys
Reply With Quote
  #6  
Old 01-29-2004, 09:26 PM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

Quote:
Originally Posted by vnhabcml
Hi Evadman,

I have tabbed on the page (manually) and I am able to move along the page. However, when I run the program it tabs on the first page between login and password but it does not tab on the second page. I don't know why, maybe it doesn't think the second page has finished loading. Is there another method I can use to see if the page has finished loading. I noticed on Microsoft website the downloadcomplete and documentcomplete options but I do not see how it works



step through the code to see if the code is leaving the while ie.busy doevents loop. If it is, the page finished.

To see all the available methods and internal objects on the web page, put a line break or pause on the line after the second doevents, and look at the locals window to see what the IE varaible contains. You can see EVERYTHING on the web page and the heierarchy of all the objects. It is very useful. That is how I learned the litthe that I know.
Quote:
Originally Posted by vnhabcml

Also, do you know of another way that I can use the .sendkeys other than the DoEvents/SendKeys method. I noticed on the link that they used objShell.SendKeys "{TAB}". However, I am not familiar with the SHELL_OBJECT = "WScript.Shell" script.


There are sendkeys replacements, including "sendkey" which I played around with a little about 4 months ago. Unfortunately, I do not have the code any more. I did however, get it from a search here. I KNOW it was called "sendkey" without the S.

What I try to do with any ie type stuff is reference objects on the page, like you spoke a little of. such as: ie.document.all("textboxpassword").value. Stuff like that can be used for inputting data into textboxes and clicking on butons with the .click method. There are ways to pull info in tables, fields, etc. It is all listed in the locals window while your code is running.

Quote:
Originally Posted by vnhabcml

As for using sendkeys, I hate doing it as well. I noticed that you are a Attachmate guru. Unfortunately, Attachmate (Extra) is the program that got me in the habbit of using sendkeys



Me too. I have tried hard to sever all ties with sendkeys, which actually works very well in Extra. Just not in anything else
__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #7  
Old 01-30-2004, 03:49 PM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

For some reason, it is still not working. I just created a webbrowswer in excel and it is still occuring. After I hit enter on the login button, the second webpage loads and then nothing happens. I stepped through line by line and it still occurred

Now, I do not have to use the sendkeys/tab method on the second page (after it loads, which it is doing successfully), I only need to insert a WebBrowser1.Navigate method to a thid webpage. Of course, I will have to sendkeys on the third webpage. But the WebBrowser1.Navigate method is not working. Here is what I need to happen:

SendKeys ("{enter}") 'Hit the enter button on the login page

Do While WebBrowser1.Busy
Loop 'Wait for the 2nd page to load

WebBrowser1.Navigate 'Go to the third webpage

Do While WebBrowser1.Busy
Loop 'Wait for the 3rd page to load

SendKeys ("{tab}") 'Tab through the third webpage.

Any ideas? I'm sure the answer is looking right into my face. Life sure was easy when I only had to look at that black screen (Extra) all day
Reply With Quote
  #8  
Old 01-30-2004, 11:12 PM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

is this a page I can access? or is this an internal page?
__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #9  
Old 01-31-2004, 07:16 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

Unfortunately for me, it is internal.
Reply With Quote
  #10  
Old 01-31-2004, 11:46 PM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

Quote:
Originally Posted by vnhabcml
Unfortunately for me, it is internal.



There has to be a way to reference the objects on the page. All I can suggest without seeing the page is to load the page in code, but before the code ends, but after the page loads, put in a code break. Then look at the ie variable to see the objects contained within.
__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #11  
Old 02-02-2004, 11:43 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

Evadman, Thanks for all of your help. I think it will be easier for me to just write some SQL statements and have the users directly connected with the servers. Unfortunately, this will be a lot more work for me. But it seems easier than dealing with the websites.
Reply With Quote
  #12  
Old 02-03-2004, 06:34 AM
OSUAero OSUAero is offline
Newcomer
 
Join Date: Feb 2004
Posts: 2
Default

Could it be that the second webpage is using frames, and you need to redefine your object?

I am having a similar problem in which I can log onto the site with no problem, but upon loading the second page, I no longer have a properly defined Object. I suspect it is due to the second page containing frames(I know the second page is using frames), but I really don't know enough about it to deal with them.
Reply With Quote
  #13  
Old 02-04-2004, 07:50 PM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

Hi OSUAero,

This may be the situation. Have you been able to work around this. I hate it when I am not able to "fix" a problem. Also, are you using a webbrowser?

Thanks
Reply With Quote
  #14  
Old 02-05-2004, 05:19 AM
OSUAero OSUAero is offline
Newcomer
 
Join Date: Feb 2004
Posts: 2
Default

I am attempting to launch a specific file from an intranet database while inside Excel. I am using IE6 as my web browser. I haven't had any luck once I hit a page with frames. I am sure it's an easy fix, but...
Reply With Quote
  #15  
Old 02-06-2004, 11:49 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Red face

Does anyone know how to work around frames in Internet Explorer. Also, would anyone be willing to post some code where you go to a website and then navigate to a second website and then enter information on that page. I am not looking for a "hand out", I am just trying to understand if this there is another way of working around my problem. I am all out of ideas. Well, I guess I am looking for a "hand out".

Thanks
Reply With Quote
  #16  
Old 02-06-2004, 05:11 PM
Evadman Evadman is offline
Centurion
 
Join Date: Dec 2003
Location: Illinois
Posts: 113
Default

To access frames, you use the frames(identifier) method.

So if your internet explorer object variable is called IE, then you reference the frames by using:
Code:
ie.document.frames(1) 'numerical by way of page placement.
__________________
IBM Attachmate Guru. PM me if you have Attachmate Session automation questions.
Reply With Quote
  #17  
Old 02-07-2004, 10:54 PM
lilprogrammer lilprogrammer is offline
Newcomer
 
Join Date: Sep 2003
Location: NY
Posts: 19
Default

Hi,
There is a way by which you can reference all objects on a page. However, it is tedious to use since it references just ALL the objects (I think it even refernces <html> and <head> tags)

You can do this by giving:

Code:
ie.document.all(x) ' x implies the index number of the object you want ' to reference, starting from base 0

This can be used if there are no names given to objects in the browser. I have posted a detailed post on how to refernce all objects on a form at the link :
http://www.xtremevbtalk.com/showthread.php?t=123340
post #17. It is the same link Evadman has provided before.

Hope this helps

-lilpro
Reply With Quote
  #18  
Old 02-26-2004, 08:32 AM
vnhabcml vnhabcml is offline
Newcomer
 
Join Date: Jan 2004
Posts: 10
Default

I've been on vacation, sorry about the delay....But I have probably found the answer---duh. I just upgraded my internet explorer and everything seems to work. Because this will be used on the intranet, I'll be able to make the users upgrade as well. Thanks for everyone's help.
Reply With Quote
  #19  
Old 02-26-2004, 12:59 PM
P_R P_R is offline
Newcomer
 
Join Date: Feb 2004
Posts: 10
Default

I think i can help with the frames problem.

I found this out by analyzing the InternetExplorer object in the locals window.

If a Page got Frames, the

Code:
obj.document.all

collection contains - beside the header and such stuff - a FRAMESET and some FRAME nodes.

You can access the elements collection of documents in the frames like this (just assume, the 6th element in the collection is one of the frames)
Code:
obj.document.all(6).contentWindow.document.all

if you need to click a link, here is a example(just assume the 20th in the frame is a link):

Code:
obj.document.all(6).contentWindow.document.all(20).click

if you got the name of the link and the name is unique you can also try

Code:
dim i as integer for i = 1 to obj.document.all(6).contentWindow.document.all.length step 1 if(obj.document.all(6).contentWindow.document.all(i).innerText = "NAME") then obj.document.all(6).contentWindow.document.all(i).click end if next i


i hope this is useful ;-)

Last edited by P_R; 02-27-2004 at 02:52 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
populate internet explorer forms with excel data lilprogrammer Word, PowerPoint, Outlook, and Other Office Products 23 12-30-2008 11:37 AM
is internet explorer open 14yrsgirl General 10 01-01-2004 04:45 PM
Chatting with Internet Explorer danopolitan Communications 2 10-02-2003 03:33 PM
Internet Problems Billybob54 Tech Discussions 4 06-27-2002 09:05 PM
Printer settings for Internet Explorer Object Roopak General 0 11-09-2001 04:03 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->