Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Web page loading
Does anyone have a non-time based vba code that allows vba
to detect when a web page has loaded after focus has been thrown to Internet Explorer from Excel using Appactivate? Currently I am inserting data from a text file into specific fields on a web page and then pressing a button on the page to receive the results. The results are then saved using IE's "save as" function. However, since the internet is not instantaneous, I need to have a way to detect that the web page has been loaded. Using a timer doesn't work since the amount of time is random and assigning an estimated time means that the wait time has to be adjusted every time this program runs. Any advice about how to detect whether the page has loaded? Thanks, Matt |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Web page loading
Hi Matt,
You can do this if you are Automating Internet Explorer, but I don't know if you can using AppActivate. Here are the basics of doing it via Automation: Sub test23() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate URL:="http://www.longhead.com/" Do While ie.Busy Or Not ie.ReadyState = _ READYSTATE_COMPLETE DoEvents Loop MsgBox ie.Document.body.innertext ie.Quit Set ie = Nothing End Sub You must set a reference to Microsoft Internet Controls in order to use this. Or you can use Late Binding if you don't want to set a reference. You can also sink the Internet Explorer events so you don't have to make the user wait for the document to load - you can just call another subroutine or take a specific action once the DocumentComplete event fires. This is a bit tricky, but if you'd like to see some sample code, I'd be happy to post it for you. -- Regards, Jake Marx www.longhead.com Matt Cohen wrote: Does anyone have a non-time based vba code that allows vba to detect when a web page has loaded after focus has been thrown to Internet Explorer from Excel using Appactivate? Currently I am inserting data from a text file into specific fields on a web page and then pressing a button on the page to receive the results. The results are then saved using IE's "save as" function. However, since the internet is not instantaneous, I need to have a way to detect that the web page has been loaded. Using a timer doesn't work since the amount of time is random and assigning an estimated time means that the wait time has to be adjusted every time this program runs. Any advice about how to detect whether the page has loaded? Thanks, Matt |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Web page loading
Jake: Thank you for your response. I am not familiar with the references you mentioned, Microsoft Internet Controls and Late Binding. Are these Options declared prior to the sub? Your code would provide what I need once I understand these. I appreciate any help you could provide. Thanks, Matt -----Original Message----- Hi Matt, You can do this if you are Automating Internet Explorer, but I don't know if you can using AppActivate. Here are the basics of doing it via Automation: Sub test23() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate URL:="http://www.longhead.com/" Do While ie.Busy Or Not ie.ReadyState = _ READYSTATE_COMPLETE DoEvents Loop MsgBox ie.Document.body.innertext ie.Quit Set ie = Nothing End Sub You must set a reference to Microsoft Internet Controls in order to use this. Or you can use Late Binding if you don't want to set a reference. You can also sink the Internet Explorer events so you don't have to make the user wait for the document to load - you can just call another subroutine or take a specific action once the DocumentComplete event fires. This is a bit tricky, but if you'd like to see some sample code, I'd be happy to post it for you. -- Regards, Jake Marx www.longhead.com Matt Cohen wrote: Does anyone have a non-time based vba code that allows vba to detect when a web page has loaded after focus has been thrown to Internet Explorer from Excel using Appactivate? Currently I am inserting data from a text file into specific fields on a web page and then pressing a button on the page to receive the results. The results are then saved using IE's "save as" function. However, since the internet is not instantaneous, I need to have a way to detect that the web page has been loaded. Using a timer doesn't work since the amount of time is random and assigning an estimated time means that the wait time has to be adjusted every time this program runs. Any advice about how to detect whether the page has loaded? Thanks, Matt . |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Web page loading
Hi Matt,
If you go to the VBE and select Tools | References, look for Microsoft Internet Controls and check the box next to it. That will allow Excel to use the necessary library for the code to work as written. Late Binding refers to using the library without referencing it in your VBA project. To do this, you would have to declare ie As Object, use CreateObject to create an instance of the IE application, and replace the READYSTATE_COMPLETE constant with its actual value (4). If you do all these things, you don't need to set a reference to the library to get your code to work. Late Binding is a lot slower if you're making a lot of calls to the library, but in this case, you probably won't notice a difference. Late Binding is nice in that you don't have to worry about whether the user will have a different version of a library on his/her machine. And you can trap the runtime error generated by CreateObject if the library doesn't exist on the user's machine. With Early Binding (setting a reference and declaring As InternetExplorer), you cannot trap the error the user will get if he/she doesn't have the necessary library on the machine. -- Regards, Jake Marx www.longhead.com Matt Cohen wrote: Jake: Thank you for your response. I am not familiar with the references you mentioned, Microsoft Internet Controls and Late Binding. Are these Options declared prior to the sub? Your code would provide what I need once I understand these. I appreciate any help you could provide. Thanks, Matt -----Original Message----- Hi Matt, You can do this if you are Automating Internet Explorer, but I don't know if you can using AppActivate. Here are the basics of doing it via Automation: Sub test23() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate URL:="http://www.longhead.com/" Do While ie.Busy Or Not ie.ReadyState = _ READYSTATE_COMPLETE DoEvents Loop MsgBox ie.Document.body.innertext ie.Quit Set ie = Nothing End Sub You must set a reference to Microsoft Internet Controls in order to use this. Or you can use Late Binding if you don't want to set a reference. You can also sink the Internet Explorer events so you don't have to make the user wait for the document to load - you can just call another subroutine or take a specific action once the DocumentComplete event fires. This is a bit tricky, but if you'd like to see some sample code, I'd be happy to post it for you. -- Regards, Jake Marx www.longhead.com Matt Cohen wrote: Does anyone have a non-time based vba code that allows vba to detect when a web page has loaded after focus has been thrown to Internet Explorer from Excel using Appactivate? Currently I am inserting data from a text file into specific fields on a web page and then pressing a button on the page to receive the results. The results are then saved using IE's "save as" function. However, since the internet is not instantaneous, I need to have a way to detect that the web page has been loaded. Using a timer doesn't work since the amount of time is random and assigning an estimated time means that the wait time has to be adjusted every time this program runs. Any advice about how to detect whether the page has loaded? Thanks, Matt . |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Web page loading
Jake:
Thanks again for your help. Matt -----Original Message----- Hi Matt, If you go to the VBE and select Tools | References, look for Microsoft Internet Controls and check the box next to it. That will allow Excel to use the necessary library for the code to work as written. Late Binding refers to using the library without referencing it in your VBA project. To do this, you would have to declare ie As Object, use CreateObject to create an instance of the IE application, and replace the READYSTATE_COMPLETE constant with its actual value (4). If you do all these things, you don't need to set a reference to the library to get your code to work. Late Binding is a lot slower if you're making a lot of calls to the library, but in this case, you probably won't notice a difference. Late Binding is nice in that you don't have to worry about whether the user will have a different version of a library on his/her machine. And you can trap the runtime error generated by CreateObject if the library doesn't exist on the user's machine. With Early Binding (setting a reference and declaring As InternetExplorer), you cannot trap the error the user will get if he/she doesn't have the necessary library on the machine. -- Regards, Jake Marx www.longhead.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
loading add ins | Excel Discussion (Misc queries) | |||
Loading... | Excel Discussion (Misc queries) | |||
loading | Excel Discussion (Misc queries) | |||
Loading a Different Page | Excel Discussion (Misc queries) | |||
Add-ins not loading | Excel Discussion (Misc queries) |