Download File, Copy Text To Clipboard

  • Thread starter Thread starter Scott Pendleton
  • Start date Start date
S

Scott Pendleton

A Web site has 1,000 hyperlinks, each pointing to a different text file with
a .abc extension. I have loaded the document names into an Access table,
intending to write a program to download the files. To that end, I have set a
reference to the Microsoft HTML Object Library, so I can create and control
an instance of MSIE.

Problem 1: MSIE won't display a file with a .abc extension. Instead, it pops
up the dialog box to "save or run". So that prevents looping through all the
files.

Workaround: Set my computer to use Notepad to open .abc files. Now the MSIE
instance throws the file into a new instance of Notepad automatically.

Problem 2: SendKeys utterly fails to effect a Ctrl-A, Ctrl-C on the Notepad
instance, even after doing an AppActivate, and even if I loop multiple times,
checking each time to see if the contents of the Clipboard have changed.
Thus, I can't get the file contents into a string that I could save as a new
file with the FileSystemObject.

Problem 3: I don't have a way programmatically to tell the new Notepad
instance to "Save As".

Problem 4: I don't know how to read the contents of the Notepad instance
from their location in memory.

Queston 1: Is there a way to download the files other than using an MSIE
instance? (The site doesn't give any FTP options.)

Question 2: Is there a way to make MSIE display the contents of the text
file ending in .abc?

Question 3: How do I copy the contents of a Notepad instance, remembering
that those contents have not yet been saved as a file?

Thanks,
Scott
 
Scott Pendleton said:
A Web site has 1,000 hyperlinks, each pointing to a different text file
with
a .abc extension. I have loaded the document names into an Access table,
intending to write a program to download the files. To that end, I have
set a
reference to the Microsoft HTML Object Library, so I can create and
control
an instance of MSIE.

Problem 1: MSIE won't display a file with a .abc extension. Instead, it
pops
up the dialog box to "save or run". So that prevents looping through all
the
files.

Workaround: Set my computer to use Notepad to open .abc files. Now the
MSIE
instance throws the file into a new instance of Notepad automatically.

Problem 2: SendKeys utterly fails to effect a Ctrl-A, Ctrl-C on the
Notepad
instance, even after doing an AppActivate, and even if I loop multiple
times,
checking each time to see if the contents of the Clipboard have changed.
Thus, I can't get the file contents into a string that I could save as a
new
file with the FileSystemObject.

Problem 3: I don't have a way programmatically to tell the new Notepad
instance to "Save As".

Problem 4: I don't know how to read the contents of the Notepad instance
from their location in memory.

Queston 1: Is there a way to download the files other than using an MSIE
instance? (The site doesn't give any FTP options.)

Question 2: Is there a way to make MSIE display the contents of the text
file ending in .abc?

Question 3: How do I copy the contents of a Notepad instance, remembering
that those contents have not yet been saved as a file?

Thanks,
Scott

You could try Dev's HTTP object - no need for IE or notepad. You can get it
here:

http://www.mvps.org/access/modules/mdl0037.htm
 
There's an API function named URLDownloadToFile that you can use. Its
declaration is:

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

Here's a sample function that uses it:

Private Function DownloadFile( _
URL As String, _
LocalFilename As String _
) As Boolean
On Error GoTo Err_DownloadFile

Dim lngRetVal As Long

lngRetVal = _
URLDownloadToFile(0, URL, LocalFilename, 0, 0)
DownloadFile = (lngRetVal = 0)

End Function

You'd pass it the name of the URL and the name of the file to which you want
to save the contents of that URL. (URL can be anything, including graphics
files).
 
Great answers! I'd still like to have an answer to Question 3 below, just for
future reference...
 
I'm not sure there's any reliable method to do so, since you can't automate
Notepad.
 
Back
Top