PDA

View Full Version : wildcard character is not working while opening excel file



syed_iqbal
04-22-2017, 02:36 PM
Hi,

iam using below code (by using wildcard character "*" ) to open excel file. but it showing error

kpath = ThisWorkbook.Path & "\"
Workbooks.Open Filename:=kpath & "usd project*.xlsx"

Error: Run-time error '1004':
"Sorry, we couldn't find C:\Users\syed\Desktop\pipeline\usd project*.xlsx. Is it possible to moved, renamed or deleted?"

regards
syed

Paul_Hossler
04-22-2017, 02:53 PM
Why are you using a wild card to open a file like that?

Did you want to open a FileOpen dialog box and pick a file to open that matches the mask "usd project*.xlsx" ?

syed_iqbal
04-22-2017, 03:07 PM
HI,

thank you for reply. I want to open the file automatically by using filepath only. there are some files like "usd project pipeline", "gbp project pipeline", "inr project pipeline", "chn project pipeline". from these files, i want to open "usd project pipeline". pls help.

Paul_Hossler
04-22-2017, 05:03 PM
HI,

thank you for reply. I want to open the file automatically by using filepath only. there are some files like "usd project pipeline", "gbp project pipeline", "inr project pipeline", "chn project pipeline". from these files, i want to open "usd project pipeline". pls help.


Why not just ...



kpath = ThisWorkbook.Path & "\"
Workbooks.Open Filename:=kpath & "usd project pipeline.xlsx"

syed_iqbal
04-22-2017, 07:35 PM
your code is working. my doubt is, Can't we open the file by using wildcard character.

Paul_Hossler
04-23-2017, 06:19 AM
If you have this ...




Workbooks.Open Filename:=kpath & "usd project pipeline*.xlsx"



and there are files named ...

usd project pipeline 2015.xlsx
usd project pipeline 2016.xlsx
usd project pipeline 2017.xlsx

how would Excel know which one to open?

Now if you wanted to open ANY and ALL files that matched "usd project pipeline*.xlsx", there are ways to do that. Just not using the .Open like you used. You would need a Dir() loop