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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a Document object 2

Status
Not open for further replies.

Reuel

Programmer
Dec 27, 2004
45
US
In the following code, I expect to get Google's logo saved to my E drive.

Code:
WebBrowser1.Navigate "[URL unfurl="true"]http://www.google.com/images/logo.gif"[/URL]
WebBrowser1.Document.ExecCommand("SaveAs", False, "e:\test.gif")

What I get instead is the Save Picture dialog box with the default path (My Pictures) and the original file name, "logo.gif". Can anybody tell me what I'm doing wrong? I know there are other ways to do this, but when I think I'm doing something right, and it doesn't work, I have to find out WHY!

Thanks!
 
You haved saved the day! I tried it, and the application is running at 100%! No problems whatsoever! Yeehaw!
 
Reuel, Harleyquinn, thanks to you both. This is exactly what I want to be able to do. But I am still having troubles. I am using VB6.0.

Although I followed Harleyquinn's advise, I am not able to make it work. I get the error message: "Compile Error, User-defined type not defined". In debugging the code, it is hung up at the first line of the sub:
Dim collImages As IHTMLElementCollection

Any thoughts?
Thank you!!
 
I tried the simpler version as outlined at:

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

returnValue = URLDownloadToFile(0, " "c:\test.gif", 0, 0)

However, I get the following error message:
Compile Error: Invalid Outside Procedure
The first 0 (before the url) is highlighted

I have Windows Internet Components reference loaded. I have urlmon.dll in my system32 folder.

Any thoughts???
Thanks!
 
Hi lag1,

The code posted by yourself in your second post works perfectly for me. I have tried everything I can think of to re-create your error and have been unable to do it. I have even tried unregistering the DLL and still no joy.

It might be that we are working with different versions of the DLL??? Mine is version 6.0.2800.1485.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
For the first example you need to reference the Microsoft HTML object library.

For the second example, the declaration goes in the declarations section at the top of your Form Module and the rest goes in a procedure e.g.

Private Sub Command1_Click()
Dim returnValue As Long
returnValue = URLDownloadToFile(0, " "c:\test.gif", 0, 0)
End Sub


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
johnwm,
Thank you so much for recognizing just how basic my knowledge is. It works perfectly!

Harleyquinn,
Thank you for your post to Reuel or I'd never have gotten on the right track at all.

Thank you, Thank you!
Actually, this seems an appropriate time to shout:
THANK YOU! YES!
 
Well, it works SOMETIMES. I think there is a timing problem. Not all images download. I'm trying this on a directory of 34 images. The program is going right down a comma delimited list and getting the image off the web and saving it onto my harddrive. However, it always downloads the same 20 images, skipping over the same 14.

If I step through the program, I get a recordvalue = -2146697210 for those that don't download and a recordvalue = 0 for those that do.

However, if in my browser I manually open the URL that I want to save then run my little program, it works for that file

My thought is that my program executes faster than the image loads. Is there a way to slow down the process?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top