Excel VBA to open a CSV file on an FTP server

the_tones

New Member
Joined
Sep 5, 2014
Messages
3
Sorry pretty much a newbie on VBA. Trying to use VBA to open a CSV file on a FTP server with username and password. Server is an IP address. I found the code below on another thread and am confused on the FilePath line and what I put in for "@ftp.XXXXXXX.com/MEMCARD1/FC_files/flow.csv". Where MEMCARD1/FC_files/flow.csv/flow,csv is file I am trying to open on IP address 172.16.0.10. Any help is appreciated. Thanks

Sub test()


Dim FTPuser, FTPpassword, FilePath, RawWB

FTPuser = "username"
FTPpassword = "password"

FilePath = "ftp://" & FTPuser & ":" & FTPpassword & "@ftp.XXXXXXX.com/MEMCARD1/FC_files/flow.csv"

Set RawWB = Workbooks.Open(Filename:=FilePath, ReadOnly:=True)
RawWB.Activate


End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Figured this out. However if I run the following script several times I get a message that can't connect to the FTP server. It will work for 3 or 4 times and then error out. The FTP server is on a PLC and I'm grabbing data from a CSV file. Anyone know why it will stop working after 3 or 4 runs?

Sub ImportMixedData()
Application.ScreenUpdating = False
co = Cells(7, 2).Value
Set BS = ActiveWorkbook
username = "Bench01"
password = "K444"
Workbooks.Open Filename:="ftp://" & username & ":" & password & "@172.16.0.10/MEMCARD1/FC_FILES/FC_DATA.CSV"
range("D2:D27, G2:G27").Select
Selection.Copy
'Paste data on flow curve in request file
BS.Activate
Cells(30, 2).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Application.DisplayAlerts = False
Workbooks("FC_DATA.CSV").Close savechanges:=False
Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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