VBA - Download from FTP

mwheatley

New Member
Joined
Dec 13, 2016
Messages
2
Hi

I have the code below attached to a button in a macro. This is the code in complete and I have been using it to test taking the information from a file on my computer. This works fine, it all plugs in to the right place - no issue.

Now that file is on my ftp server which is user and password protected. *I have literally no idea how to go about downloading or (preferably) opening this file from the ftp*

Could anyone help me out with how to download my file?


Code:
Sub ImportTextFile()

Application.ScreenUpdating = False


    Password = "ABC"
    UserName = "ABC"
    Filename = "ABC"
    Serverlocation = "ftp:www.abc.com\"


     INSERT CODE TO DOWNLOAD FILE FROM FTP SERVER HERE






myTextFile = Workbook.Open(-------)


Dim lastCol As Long
lastCol = ThisWorkbook.Sheets("Continuity").Cells(4, Columns.Count).End(xlToLeft).Column
 
   myTextFile.Sheets(1).Range("A4:A11").Copy
   ThisWorkbook.Sheets("Continuity").Cells(4, lastCol + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
    If myTextFile.Sheets(1).Range("A5") = ThisWorkbook.Sheets("Continuity").Cells(5, lastCol) Then
    ThisWorkbook.Sheets("Continuity").Cells(4, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(5, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(6, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(7, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(8, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(9, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(10, lastCol + 1).ClearContents
    ThisWorkbook.Sheets("Continuity").Cells(11, lastCol + 1).ClearContents
    
     
    End If


myTextFile.Close = False
Application.ScreenUpdating = True


End Function
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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