简体   繁体   中英

How to Open a FTP file with a * wild character in Name Using VBA

I want to open a file from a folder in FTP Site. This folder has multiple reports with the same name only difference is timestamp ie Reports for each day

So i was trying to use a Wild Character * in my code to pick up todays report , see the code below

sReportDate = Format(ReportDate, "mmddyy")
ReportName = "_______Notification_of_Separation_______.POSFTPADPRFT1JFAGP02." &   sReportDate  & "*.csv" 

Workbooks.OpenText fileName:="ftp://UserID:Password@IPAddress/Separation Notifications/" & ReportName 

but it is not working and doesn't opens the file.

however if i hard code the report name it works, there is some thing wrong with wild character.

Any help ??

From Excel VBA Help:

FileName Required String . The file name of the workbook to be opened

Names of individual files on Windows systems (and I guess you are running Excel under Windows) cannot contain wildcard characters. You must specify the exact filename of the file you want to open.

Since you say all the files in the directory have "the same name only difference is timestamp", and you are providing that in sReportDate , why is the wildcard needed anyway?

If in fact the filename has a variable timestamp after the date, then you will need to interrogate the folder to find the relevant file to open. There's a start with doing that in another question: Does Dir() make any guarantee on the order of files returned? You can use wildcards when you are examining filenames in a directory — then, having found one which matches your date, you know the relevant name and can open it explicitly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM