Hi People,
I have a link in my vba code:
Application.FollowHyperlink "http://www.xxxxxx.co.uk/"
but I dont want to open a browser (or show it minimised) but need to dump the resultant html page to a text file to search for a string.
I have tried:
Application.FollowHyperlink "http://www.xxxxxx.co.uk/" >c:\temp.txt
but that doesnt work.
Any ideas?
Hi Neopa
Yes I normally use option explict, but the code is something that I threw together in about 15 minutes, for the sole purpose of answering the posted question. So to answer your question I did not use Option explicit and the posted code is complete.
I hope I can be forgiven for the bad programming practice because, I can try and excuse it with the simplicity of the program but there is no excuse in reality :{
No offence is taken, you are just....right!
As to the "Microsoft Internet Controls" library, that is definitely the one.
I also have a reference to the "Microsoft HTML Object" Library, so I tried removing the reference to the "Microsoft Internet Controls" and then checked intellisense by typing a space immediately after "As" in
Private ieBrowser As InternetExplorer
and there was no InternetExplorer in the list.
so its definitely "Microsoft Internet Controls"
The code is actually written from ideas presented on a few sites I found with google. Much of the code was copy paste as evidenced by the variable you point out sDocHTML. My normal practice would have it as strDocHTML
Anyway, here is a cleaned up version of the code -
Option Compare Database
-
Option Explicit
-
-
Private ieBrowser As InternetExplorer
-
-
Private Sub Form_Load()
-
Dim strDocHTML As String, dteStartTime As Date
-
'Create a browser object
-
Set ieBrowser = CreateObject("internetexplorer.application")
-
ieBrowser.Navigate "http://www.delerna.com/Index.asp"
-
-
'Wait for the page to load. Exit Form_load sub, doing nothing, if loading the page takes too long
-
dteStartTime = Now
-
Do While ieBrowser.readyState <> READYSTATE_COMPLETE
-
If DateDiff("s", dteStartTime, Now) > 240 Then Exit Sub
-
Loop
-
-
'Get the page contents
-
strDocHTML = ieBrowser.Document.documentElement.innerHTML
-
-
'And save it
-
Open "c:\Test.txt" For Output As 1
-
Print #1, strDocHTML
-
Close #1
-
-
'destroy the browser object
-
Set ieBrowser = Nothing
-
End Sub
-
9 11838 NeoPa 32,556
Expert Mod 16PB
I cannot help much, other than to point you towards the Microsoft Web Browser OLE class. It needs a Reference set up to the Microsoft HTML Reference Library.
Hope this helps.
I'm pretty sure using the .FollowHyperlink won't get you what you want.
Here is my attempt. First time I have done this and I like it and I will use it.
Its something I have contemplated for a quite while but never got around to it.
I have kept the code as simple as possible so its workings are obvious.
You will need to add error checking etc etc. Step 1
add a reference to the "Microsoft Internet Controlls" type library Step 2
add the code and modify for your situation -
Private ieBrowser As InternetExplorer
-
-
Private Sub Form_Load()
-
'Create a browser object
-
Set ieBrowser = CreateObject("internetexplorer.application")
-
ieBrowser.Navigate "http://www.delerna.com/Index.asp"
-
-
'Wait for the page to load
-
dtStartTime = Now
-
Do While ieBrowser.readyState <> READYSTATE_COMPLETE
-
If DateDiff("s", dtStartTime, Now) > 240 Then Exit Sub
-
Loop
-
-
'Get the page contents
-
sDocHTML = ieBrowser.Document.documentElement.innerHTML
-
-
'And save it
-
Open "c:\Test.txt" For Output As 1
-
Print #1, sDocHTML
-
Close #1
-
-
'destroy the browser object
-
Set ieBrowser = Nothing
-
End Sub
-
Good luck and thanks for influencing me to actually sit down and finally do it.
NeoPa 32,556
Expert Mod 16PB @Delerna
I found a Microsoft HTML Object Library reference Delerna, but nothing similar to that :S
NeoPa 32,556
Expert Mod 16PB
Like you I think I'm ready to start playing in this area. I'd be interested in following your code more closely, but I find there are items which are not declared (sDocHTML, etc). Is this because it's declared elsewhere or do you not have Option Explicit set? I ask this not to criticise you understand, but if you don't use this as standard then may I suggest you reconsider that approach. I have a short article on the matter here ( Require Variable Declaration).
Again, I expect you may be doing this already and just omitted a couple of lines of your code. In that case please just ignore this (but I'm interested in the full code anyway ;)).
Hi Neopa
Yes I normally use option explict, but the code is something that I threw together in about 15 minutes, for the sole purpose of answering the posted question. So to answer your question I did not use Option explicit and the posted code is complete.
I hope I can be forgiven for the bad programming practice because, I can try and excuse it with the simplicity of the program but there is no excuse in reality :{
No offence is taken, you are just....right!
As to the "Microsoft Internet Controls" library, that is definitely the one.
I also have a reference to the "Microsoft HTML Object" Library, so I tried removing the reference to the "Microsoft Internet Controls" and then checked intellisense by typing a space immediately after "As" in
Private ieBrowser As InternetExplorer
and there was no InternetExplorer in the list.
so its definitely "Microsoft Internet Controls"
The code is actually written from ideas presented on a few sites I found with google. Much of the code was copy paste as evidenced by the variable you point out sDocHTML. My normal practice would have it as strDocHTML
Anyway, here is a cleaned up version of the code -
Option Compare Database
-
Option Explicit
-
-
Private ieBrowser As InternetExplorer
-
-
Private Sub Form_Load()
-
Dim strDocHTML As String, dteStartTime As Date
-
'Create a browser object
-
Set ieBrowser = CreateObject("internetexplorer.application")
-
ieBrowser.Navigate "http://www.delerna.com/Index.asp"
-
-
'Wait for the page to load. Exit Form_load sub, doing nothing, if loading the page takes too long
-
dteStartTime = Now
-
Do While ieBrowser.readyState <> READYSTATE_COMPLETE
-
If DateDiff("s", dteStartTime, Now) > 240 Then Exit Sub
-
Loop
-
-
'Get the page contents
-
strDocHTML = ieBrowser.Document.documentElement.innerHTML
-
-
'And save it
-
Open "c:\Test.txt" For Output As 1
-
Print #1, strDocHTML
-
Close #1
-
-
'destroy the browser object
-
Set ieBrowser = Nothing
-
End Sub
-
NeoPa 32,556
Expert Mod 16PB
Perfectly timed Delerna :)
I was just answering a thread where the OP wanted information about the public facing IP address they were published as (I know. Don't even ask). I tried to explain why this was less straightforward than they imagined but ...
Anyway, I wanted to post a link to this thread but I was struggling to find it again. At this point you posted. Nice one!
FYI: The other thread is Anyone out there have a clean Get_External_IP_Address function?.
Where to get "Microsoft Internet Controls"
I had the impression from the web sites that I visited that it was included with access. I have Access 2003.
I rarely use Access these days, we use asp and html as front ends to SQL server. Thats part of the reason I come here to answer questions...it maintains my access skillset....Access is a great tool and it also happens to be where I learned much of what I know.
Anyway, if it's not part of access then I also have installed on my computer.
Dot Net Framework SDK v2.0
Visual Web Dexeloper 2008 Express
and Visual Studio Pro 2005
Maybe it came from one of those?
I had a need to download the content of a web page on a regular basis so that I could monitor the current state of some facts and figures. So I wrote a vbscript version of the above so I could schedule it. I don't know if anyone is interested but I thought I would post it here.
The conversion was not very difficult, so you probably could have figured it out anyway. -
const READYSTATE_COMPLETE=4
-
-
Dim ieBrowser
-
'Create a browser object
-
Set ieBrowser = CreateObject("internetexplorer.application")
-
SavePageContent("c:\scripts\Test.txt","page URL")
-
Set ieBrowser = Nothing 'destroy the browser object
-
MsgBox "Done"
-
-
-
sub SavePageContent(Pth,Pge)
-
Dim strDocHTML, dteStartTime
-
-
ieBrowser.Navigate Pge
-
-
'Wait for the page to load. Exit sub, doing nothing, if loading the page takes too long
-
dteStartTime = Now
-
Do While ieBrowser.readyState <> READYSTATE_COMPLETE
-
If DateDiff("s", dteStartTime, Now) > 1000 Then Exit Sub
-
Loop
-
-
'And save it
-
Dim fso, MyFile
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
Set MyFile = fso.CreateTextFile(Pth)
-
MyFile.WriteLine(ieBrowser.Document.documentElement.innerHTML )
-
MyFile.Close
-
set MyFile=nothing
-
set fso=nothing
-
end sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bill Sneddon |
last post by:
Can any one tell me how to output the following string?
<%response.write "<tr><td><a href=""file://SERVER/mmlogs/TNAME" &
yearmonth & """>"& "MYJUNK" & "</a><BR></td></tr>" %>
...
|
by: Poster |
last post by:
I have a script, its outputs are in HTML. It displays perferctly in a
browser, however when I view source, it gives me the JS scripts, but I want
to view the HTML output. Is there a way I can view...
|
by: Wescotte |
last post by:
I'm writing a tiny php app that will log into our bank of america
account and retrieve a file containing a list of checks that cleared
the previous day. The problem I'm running into is when I...
|
by: Steve Peterson |
last post by:
Hi
I have an .aspx web form in which I would like to output only XML, no HTML.
The datasource is a datatable that's bult on the fly based on user input
from previous .aspx page so the XML output...
|
by: Skeptical |
last post by:
Hello,
I am trying to embed html output into my webform but could not figure out
how to so far.
The form will execute a Perl script with some parameters, and script will
output some html...
|
by: Andrew |
last post by:
I'm adding this as it to me a while to figure out all the pieces to be
able to do this without using Microsoft.Office.Interop which caused me
problems on the web-server.
Streaming is the easy...
|
by: astromac |
last post by:
I'm new to php and was wondering if the following was possible...
I would like to have a list of items loaded from a text file, process
each item in the list and then return the processed result...
|
by: dawnerd |
last post by:
Hi, I am developing a CMS and came across something which has never
happened to me before, and I re-wrote the specific script twice, both
differently, and still had the same error.
I'm not sure...
|
by: Jon Slaughter |
last post by:
I'm using eval to excute some mixed php and html code but I cannot debug it.
I am essentially using filegetcontents to load up a php/html file and then
inserting it into another php/html file and...
|
by: JRough |
last post by:
I'm trying to use output buffering to cheat so i can print to excel
which is called later than this header().
header("Content-type: application/xmsdownload");
header("Content-Disposition:...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |