Outlook VBA - Download from FTP VBA

Stildawn

Board Regular
Joined
Aug 26, 2012
Messages
197
Hi All

Can someone help me with this, I need to grab a file from ftp. But I dont think its like normal ftp coding.

Firstly I tried the code here: http://www.mrexcel.com/forum/excel-questions/261043-connecting-ftp-excel.html

But I dont have the Microsoft Internet Transfer Control library (in any of my software, Outlook, Word, Excel etc).

So I think that is out.

However I think our ftp at work is set up a bit weird. How I manually get the file is like this:

1. In a normal My Computer window, I navigate to a location called "pdf printer", taking the path from the My Computer window its this: "ftp://xx.xxx.112.220/" (where x's are actual numbers I've just removed them).
2. By clicking on this folder (it looks like a folder haha) we see a few other folders the one I want location is: "ftp://xx.xxx.112.220/HB/"
3. Now we see a list of PDF files, the weird thing is we can't simply click on a file and copy and then paste to our desktop. We have to open the file by double clicking.
4. This will then open the pdf into Internet Explorer, the full path in the address bar looks like it has made a temporary pdf file in: "C:\Users\tbaker\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\R8VOCGTQ\HB-11737261[1].pdf" for example.
5. We get it from here by using the built in adobe icons (either save as, or email) etc.

To access this ftp site there is no login or anything, its setup like navigating around out desktop hard drive etc.

Basically what I am trying to achieve is to simply grab a HB file from this ftp location and save/copy it to a desktop location based on VBA code like this:

Code:
job = InputBox("Enter job number")
FileCopy "[URL]ftp://xx.xxx.112.220/HB/HB[/URL]-" & job & ".pdf", "C:\Users\tbaker\Documents\test\HB-" & job & ".pdf"
This code doesn't work as it uses the normal FileCopy method, but you get the idea on what I am trying to achieve.

Is there anyway to do this via VBA without using the Microsoft Internet Transfer Control library?

Perhaps a route would be to open up Internet Explorer, put in an address (which would be something like: ftp://xx.xxx.112.220/HB/HB-11594004.pdf, which I would create as a variable), this then loads the pdf in internet explorer (i have tested manually), then you can go File -> Save As -> and this enables you to save the pdf to desktop (I have tried this manually so I'm hoping there is a way to do this all automatically via VBA).

Thanks
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Sorry dont worry solved it with this code:

Code:
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
  
Sub DownloadFilefromWeb()
    job = InputBox("Enter Job Number")
    Dim strSavePath As String
    Dim URL As String
    Dim ret As Long
    URL = "[URL]ftp://xx.xxx.112.220/HB/HB[/URL]-" & job & ".pdf"
    strSavePath = "C:\Users\tbaker\Documents\test\HB-" & job & ".pdf"
    ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
    If ret = 0 Then
        MsgBox "Download has been succeed!"
    Else
        MsgBox "Error"
    End If
End Sub

Thanks anyway. :)
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,699
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top