DIR - Excel VBA function

Joined
Jan 21, 2018
Messages
1
Reaction score
0
Code:
Dim mypath as string

Dim nychoice as string

Mychoice = “2017”

Mypath = activeworkbook.path

mypath = mypath & "\"

mypath = mypath & Str(mychoice) & " Car Hire Log.xlsm"

MsgBox ("PATH= ") & mypath

‘’at this point mgbox returns correct valid path

If dir(mypath) <>””

Workbooks.open mypath

Else

               Msgbox(“file not found”)

Endif

Problem is workbook.open never finds file

Can anyone explain why this does not work please
 
Last edited by a moderator:
I detected the problem in your code. If you omit Str() from your code your code will start working

mypath = Trim(mypath & mychoice) & " Car Hire Log.xlsm"

In this part of code there is no need of using str() when
Mychoice = “2017” is initialized as string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need help in VBA for embedded object in excel 1
Windows XP vba code help 10
Copy item from Outlook to folder via Excel 12
Dir help 3
Detect file. 2
NEED HELP!!!! 1
Browse for folder - not selecting folder 8
Exit Sub alternative 2

Back
Top