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

Upload a gif / jpg pic with VBA

Status
Not open for further replies.

tx12345

Technical User
Jan 25, 2007
12
US
I've been using the following code for all sorts of files, and it works great, but when i try to upload a pic the image gets distorted and only a small portion of it uploads. I was looking for a better idea if possible

Code:
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\script.dat", True)
    a.WriteLine Range("a1").Text 'username
    a.WriteLine Range("a2").Text 'password
    a.WriteLine Range("a3").Text '(or "cd directory1/directory2" as needed)
    a.WriteLine Range("a3").Text 'file to be uploaded
    a.WriteLine "quit"
    a.Close
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\upload.bat", True)
    a.WriteLine Range("a4").Text 'the ftp site
    a.Close
    dRetVal = Shell("C:\upload.bat", 0) 'upload the file

i tried changing fs.CreateTextFile to fs.CreateImageFile but that generated an error

tx
 
Are you sure the ftp transfert mode is binary ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV

not sure what you mean

the above code works perfectly for text file but not pics. wndering if there is an example to successfully upload a pic

thanks

 
In the ftp script use the BINARY command before the PUT line.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ah, so it is like this:

Code:
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\script.dat", True)
    a.WriteLine Range("a1").Text 'username
    a.WriteLine Range("a2").Text 'password
    a.WriteLine "binary" '<< added here
    a.WriteLine Range("a3").Text 'file to be uploaded
    a.WriteLine "quit"
    a.Close
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\upload.bat", True)
    a.WriteLine Range("a4").Text 'the ftp site
    a.Close
    dRetVal = Shell("C:\upload.bat", 0) 'upload the file

thanks


tx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top