View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tim Williams[_4_] Tim Williams[_4_] is offline
external usenet poster
 
Posts: 114
Default Excel VBA to acess currently open web page (existing IE6 insta


document.body.innerHTML

should do it. Without seeing the page you're trying to capture it's
hard to know what else to suggest.

Tim

On Jul 14, 3:30*pm, ker_01 wrote:
Thanks Steve and Tim- this definitely has me on the right track.

Turns out that the content is not within the innerHTML, and I've been
googling and checking MSDN for syntax to return all, but so far no luck. If
you happen to come back to this thread, I'd welcome any syntax hints on how
to return the full page source, which I can then parse with RegEx.

Many thanks,
Keith



"Steve Yandl" wrote:
Keith,


What I show below might get you close. *The line
strPartURL = "google"
should be amended so the string on the right is some portion of the URL for
the page you will have open (this is to prevent problems if you happen to
have multiple web pages open at once). *I used google for the test.


Note that this delivers the inner html for the body of the document which is
not delivering as much as you get when you right click and use View Source.
If it doesn't deliver what you need, I suspect you can work with the "All"
collection and retrieve the specific text you're after. *This at least shows
you how to capture content from already open IE windows.


'-------------------------------------------


Sub GetInnerHTML()


Dim strHTML As String
Dim strPartURL As String
Dim strPageHTML As String


strPartURL = "google"


Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows


If objShellWindows.Count = 0 Then
* * Exit Sub
End If


For i = 0 To objShellWindows.Count - 1
* * Set objIE = objShellWindows.Item(i)
* * If InStr(objIE.LocationURL, strPartURL) Then
* * * * Set rng = objIE.Document.Body.CreateTextRange
* * * * strPageHTML = rng.htmlText
* * End If
Next i


MsgBox strPageHTML


Set objShellWindows = Nothing
Set objShell = Nothing
End Sub


'------------------------------------------


Steve Yandl


"ker_01" wrote in message
...
Don- thank you for your generous offer. Unfortunately, the URL is on a
secure
site, and I have no way to give access to others; the good news is that I
can
right-click and I see that the page source contains the information I want
to
scrape with RegEx, so really any web page will do.


Here is a test case:
* Open IE
* Navigate towww.google.com(or an alternate address of your preference)
* Click View/Source - this will bring up the page source in notepad


The part I'm missing is how to get this source automatically from an
"already open" IE window into Excel as a string. With Google it would be
easy
to open the URL directly from Excel VBA, but my challenge is to capture
that
text string directly from an already open browser window.


I've been abusing code snippets from all sorts of sources (non-VBA sites,
etc) but haven't gotten anywhere. I expect it will be something like:


Dim IE As SHDocVw.InternetExplorer
Do
* *MsgBox IE.document '.body.innerHTML?
Loop


I appreciate your time and expertise, and any advice you might be able to
offer.


Thank you!
Keith


"Don Guillett" wrote:


There may be a way but witout seeing all the info, it's hard to say. Give
urls and the desired. OR,
* * * If desired, send your file to my address below along with this msg
and
a clear explanation of what you want and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"ker_01" wrote in message
...
Thanks to Ron and ryguy for responses to an earlier thread- I asked my
question poorly and the thread died, so here goes another try.


I have a series of web pages that for the sake of convenience, I really
can't access programatically with Excel (I know it is probably
possible,
but
there are several pages of data entry to get to the target pages, and
it
isn't practical)


So, I'm perfectly willing to access the web page directly in IE6.
However,
I
want to scrape the target page's source and pull a bunch of data into
Excel.
This web page design prevents copy/paste, so my only way to scrape the
data
is from the page source (or hand-retype all the data, which is what I'm
trying to avoid).


I haven't found any information on how to get Excel to interact with an
existing IE6 instance and grab the page source on the fly (when a macro
runs). Can anyone point me in the right direction?


Also, I'm currently on IE6, but if a newer version of IE would make
this
easier to program, I'd consider upgrading.


Many thanks,
Keith- Hide quoted text -


- Show quoted text -