Can I have an or statement within a string when using Dir to look for files/folders?

  Kiến thức lập trình

I’m currently trying to create a program that will take an input from user that is a number eg. 58, 313, 490 and find the file with that number in it. To overcome it having multiple outputs, such as someone inputting 10 and it finds 10, 101, 102, 103, etc. I wanted to write a statement in Dir that would overcome this. The problem is that some files are titled as "### *.xlxs" and some are "###_*.xlsx" so I wanted to write a statement that would take both of these into account.

So far I have tried

filename = Dir(Uinput & (" " Or "_") & "*" & ".xlsx", vbDirectory)

I expected it to take either a space or a _ and work correctly

With this I get runtime error 13: type mismatch
Can I have an or statement within this or do I need another workaround? I’m very new to VBA and programming. Any help is appreciated, thanks.

New contributor

lemster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT