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.
 
Back
Top