Solved

Copy displayed web page text with vba

Posted on 2014-12-03
7
2,338 Views
Last Modified: 2014-12-07
I need to copy the displayed text from a web page to a string.  The text is generated by the web page and not available directly from the source.  I need to obtain with vba code the same result I would get from manually selecting the entire web page text, copying it to clipboard, then pasting it into notepad.  I am using MS Office 2014 (Access).
0
Comment
Question by:riverguy
7 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40480828
You need to automate your web browser to copy the text from the DOM.
0
 

Author Comment

by:riverguy
ID: 40482209
ste5an, thanks for the answer.  I'm not familiar with using DOM.  Would you mind giving me an example.  The information I want is not available in the source HTML, but is obtained by embedded javascript within it.   The web page is a movie schedule at http://www.fandango.com/theaterpage-prn.aspx?tid=AAWVN&date=12%2f4%2f2014 where the date elements are included in the URL.  I want to copy the output string.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 150 total points
ID: 40482681
You can get the HTML quite easily with the MSXML2.XMLHTTP object.  What are you doing with the "text" on the page?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:riverguy
ID: 40485187
I was mistaken, the text I'm looking for is available in the source text of the web page and I can get it as you suggested with an MSXML2 object in .responseText in the HTML format.  I'll have to ferret out pulling the data from the HTML.  I'm wondering if there is an object property that represents the output text, the same text one would get with selecting and copying to the clipboard all the contents of the web page, or will it have to be parsed out node by node?  I can probably go it from here.  Thanks for the help.  I'm open to any suggestions for extracting the output text.
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 350 total points
ID: 40485199
To get the entire innertext of a web page use the "Microsoft HTML Object Library"
'add a reference to Microsoft WinHttp Services 5.0
'add a reference to Microsoft HTML Object Library

Private Sub CommandButton1_Click()
    Dim Req As New WinHttpRequest
    Dim RT As String, HasData As Boolean
    Dim Doc As New HTMLDocument
    
    Req.Open "GET", "http://en.wikipedia.org/wiki/Rashmi_Gautam"
    Req.Send
    RT = Req.ResponseText

    Set Doc = New HTMLDocument
    Doc.Clear
    CallByName Doc, "Write", VbMethod, RT

    MsgBox Doc.Body.innertext
End Sub

Open in new window

0
 

Author Comment

by:riverguy
ID: 40485202
Thanks, that did it.  My mistake was in not recognizing that the information was in the HTML.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question