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:
Joined
Feb 21, 2018
Messages
216
Reaction score
86
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

Top