Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read web / download 1

Status
Not open for further replies.

Chalco

Programmer
Jul 17, 2003
32
GB
Hi,

I would like to create some code which can check a website for a particular piece of text, then depending on the value, download a file - however, I do not have any idea where to start. Can anybody provide a starter for 10, or even some sample code which I can then enhance if need be.

Thanks in advance
 
Chalco,

I could fill a ton of space giving you the code to do this. However, it's probably more educational for you to dive into the details. For starters, read up on SHDOCVW and MSHTML libraries. That should get you going.

Regards,



Randy
[afro]
 
Hi Chalco; following suggestion:
Create a New Module and put following code in it:
----------
Option Compare Database
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0

Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean

'if the API returns ERROR_SUCCESS (0),
'return True from the function
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS

End Function
-----------
Put following code behind a formbutton'OnClick' macro:
Dim FileAvailable As String
FileAvailable = DownloadFile(" "C:\PgChecked.txt")
If FileAvailable = False Then 'No connection or file not found
MsgBox "File not found!"
'Enter yr specific code here
Else
MsgBox "File successfully downloaded"
'Enter yr specific code here
End If
------------
Create link to the "C:\PgChecked.txt" -file to an accessTbl
Filter yr specific requirements.
=> Result = FoundText = True and downloaded file.

Maybe not exactly as you want it but you can tweak it.

B. Rgds & success
 
Thanks Checking, I can now (hopefully !!) get this working
 
A quick follow up to this - the code works - thanks

A follow on question though - the code uses the settings from IE, not the default browser - i.e. I have both internet explorer and firefox installed, and I use firefox by default.

Following numerous tests, I couldn't get the code to work until I reaslised that it was picking my settings up from IE rather than Firefox - Is there a way of changing this setup (not hardcoding the browser, but to use whatever the pc is using)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top