save webdata to text file

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
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.
 
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?
 
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.
 
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.
 
Back
Top