save webdata to text file

G

Guest

Even better,

Can I use transfer text to import this html table directly to a table?
The TransferText seems to indicate this but I cannot get it to work.

Bruce
 
D

Douglas J. Steele

AFAIK, TransferText will only work with a saved local copy of the html file.

To save a web page through VBA, try:

Sub SaveWebpage(URL As String)

Dim objWeb As Object
Dim intFile As Integer
Dim strFile As String
Dim strHTML As String

Set objWeb = CreateObject("Microsoft.XMLHTTP")
objWeb.Open "GET", URL, False
objWeb.send

strHTML = objWeb.responseText

strFile = CurrentProject.path & "\Saved.html"

intFile = FreeFile()
Open strFile For Output As #intFile
Write #intFile, strHTML
Close #intFile

End Sub

Pass the URL to that sub, and it will save it as a file named "Saved.html"
in the same folder as your front-end database.
 
G

Guest

Thanks Douglas,

I'll stop trying with TransferText then.

1. I want the file to save as a .csv (comma delimited). I changed a line
from your code to strFile = CurrentProject.Path & "\Saved.csv" but it loses
the comma delimitied formatting. Can you help retaining this formatting. From
here I know how to do the last part of importing a .csv into myTable.

Bruce
 
D

Douglas J. Steele

Remember that I said "TransferText will only work with a saved local copy of
the html file." That code saves the file exactly as is it on the web. In
other words, it gives you "a saved local copy of the html file".

Try using TransferText with a transfer type of acImportHTML.
 
G

Guest

Hi Douglas. I appreciate your help, but i am still having trouble.

After running your code and opening the file in Notepad, the data is
enclosed in " at the start and end of the data. If i do a file saveas from
the webpage it does not.

Is the " causing me problems?
 
D

Douglas J. Steele

Oops, guess I should have looked a little closer at the file that was
output.

Change

Write #intFile, strHTML

to

Print #intFile, strHTML

Sorry about that.
 
D

David W. Fenton

Oops, guess I should have looked a little closer at the file that
was output.

Change

Write #intFile, strHTML

to

Print #intFile, strHTML

Sorry about that.

That one always gets me, too.

I really wish Access would steal the File System Object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top