Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2005, 11:06 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading in webpages in standard Excel VBA

Hi,

I have standard Excel with Office XP.

I looking to read in a few characters from some standard HTML pages from the web (ie. do the parsing myself).

Is it possible to do this with what comes as standard in the way of functions etc? Without spending money is good. :)

Is there a way where I can I open the URL as something like a stream of text, so I can just read in the web page a character at a time?
And then close the page when I've finished.

Many thanks,

Warren
 
Old May 18th, 2005, 11:14 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could do this with Excel, although it lends itself much better to using Word as a html editor. I am presuming you want to extract the html code and not the front end.

Simpilest fashion record your macro then edit the functionality.

Cheers

Matthew

 
Old May 18th, 2005, 11:18 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help.

I'm looking to read in (mostly) numbers from the contents of the pages, and do a few operations (including some maths with them) hence Excel.
 
Old May 18th, 2005, 11:25 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excel can handle this relatively easily provided the structure of the web pages are consistant.

Copy the URL from the IE Address bar.
In excel start to record a macro.
 do file open...
 insert the copied URL in the file name box
If the workbook is uncomplicated it will always open up with the same set of numbers in the same sheet cells.
When you have finished the file open and copy/paste into a new workbook process, close the html sheet and open the next one.

Open the VBEditor with [Alt] + [F11] and look at the code. you can edit it and place loops so that is repeats the processing a number of times etc.

For any more technical question please post something specific as a new thread.

Cheers

Matthew

 
Old May 18th, 2005, 11:42 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The structure of the web page is consistent. However, because the first piece of information I read in will dictate where abouts on the web page the second piece comes from, I don't see a way I can just copy from cells. As I see it I'm going to need to read in and parse the structure of the page, just as if I was writing it in something like C++.

I suspect I'm going to need to open the web page as something like a text stream or something and just read in the text character by character and parse it. Unfortunately I've only been programming in VBA since Saturday, so kind of new to this environement. :)

As there are a few web pages I want to look at, I would like a method that is fast to read in the page and parse it rather than going through lots of code that images the page into the spreadsheet cells.

Does that makes sense?

Cheers,
Warren
 
Old May 24th, 2005, 12:44 PM
Authorized User
 
Join Date: Dec 2004
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Warren,

I think I can help, as I've been working on something similar for the past few weeks, and have basically had to teach myself. :(
You'll need to add the shdocvw reference which I believe is under "Microsoft Internet Controls".
You can open a hidden Webpage with the following code:
Set oIE = New SHDocVw.InternetExplorer
oIE.Navigate Navigateto

Then you can access it with DHTML DOM object like so.

  Spage = oIE.Document.documentElement.outerHTML

Spage will now contain most of the same stuff you would find if you opened the webpage on your own and clicked on view source. I've been able to get lots of data this way, even login to sites, and search for securities to pull data based on our holdings data. There's quite a learning curve, as, for some reason, no one has written a book about how to just make VBA and HTML/Javascript work together, so you have to sort of glean what you can from seperate sources. The MSDN website has too much information on it, but its a good place to search anyway. Good luck!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
writing and reading files on HDD from VBA out5yder Access VBA 3 October 6th, 2005 02:43 AM
Reading hardware parameters from VBA code out5yder Access VBA 5 October 6th, 2005 02:24 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.