Re: VBA and switching focus between applications



Well I think I managed to collect all the basics for IE automation thanks to
your directions, hints and your awesome site.
The next task is traversing through all possible tags/elements on a htmlpage
and then learn to handle the value/property of that object. For example
returning all strings of all tags.

As a starter for those who don't have experience with IE automating - like
me - I"ll post my starterscode. From there you should build up your skills.
Last but not least: visit the URL JP posted here. It's bloody worth it.

Private Sub CommandButton1_Click()
'Get all currently open IE and Explorer windows as the employee has multiple
instances open

Dim objShell As Shell
Dim objIE As InternetExplorer
Dim objExplorer As ShellFolderView
'Dim elem As HTMLBody <--- don't know what I can do with this one. To be
explored later
Dim doc As HTMLDocument

Dim obj As Object

Set objShell = New Shell
For Each obj In objShell.Windows
If TypeName(obj.Document) = "HTMLDocument" Then
Set objIE = obj
Set doc = objIE.Document
'Explore the contents of outerText, outerHTML, innerText and
innerHTML.
'First I want to make sure it's the Google page I'm analysing (my
employee has multiple instances open remember?).
If objIE.LocationURL = "http://www.google.nl/"; Then
Range("A1") = doc.documentElement.outerText '.outerHTML
'.innerText '.innerHTML
End If
'You can put the contents in a String variable and then parse it with
stringmanipulation-methods like InStr(), Mid(), Left, Right()
'See JP's site for an example, but these methods should be part of your
standarrepertoire anyway.
End If
Next obj
Set objShell = Nothing

End Sub

Thank you very much mr. Pena :).

"JP" <jp2112@xxxxxxxxxxxxx> schreef in bericht
news:7ec652d0-5c89-40c9-ad54-b3378c4e8d06@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have some sample code for automating Internet Explorer here:

http://codeforexcelandoutlook.com/automateinetexplorer.html
http://tinyurl.com/2twmh9

It depends on what type of website you are accessing, but a lot of
them can be accessed via code. Keep in mind it might be less tedious
to push a button, but the VBA code in many cases will be slower.


HTH,
JP

On Mar 19, 2:47 pm, "Valmont" <notrelev...@xxxxxxxxxxxxx> wrote:
An employee works with a VBA application (form in Word 2003), side by
side
with a page on Internet Explorer. From that webpage he copies manually
data to controls in the userform. This costs too much (time).

My solution would be to build additional functions in VBA. It goes like
this:
1) Press a button on the form.
2) The code behind "button_clicked" event switches focus to the open
Internet Explorer webpage (defined by the windowtitle in he blue area).
3) I use sendkeys CTRL_A then CTRL_Copy to copy the webpage contents to
the clipboard.
4) Event switches back to the VBA form (Word 2003 instance).
5) VBA code analyses the data on the clipboard and copies the right
stuff
to the controls.



.