Solved

Copy displayed web page text with vba

Posted on 2014-12-03
7
2,231 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
Backup Your Microsoft Windows Server®

Backup 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now