Hi all, please could someone explain the problem i am having.
To make this simple when i am using the CurDir property in Visual Basics it keeps displaying the wrong directory.
When my excel document loads up i want it to dislpay what directory it is saved in. So i create the function:
Private Sub Workbook_Open()
Msgbox CurDir
End Sub
in the ThisWorkbook code form. When i close down the document and go file - open etc and open the file the directory is displayed correctly, no problem there. BUT
When i close Excel down completely and double click on the document icon (let say i saved it on the desktop) it loads up excel and my document but displays the wrong directory! Very weird!
It always displays :C:\Documents and Settings\User\My Documents
No matter were it is saved!
Anyone help, please! Need this to be solved quite quickly!

Error with CurDir!
Martin.de
Thanks that clears it up a bit, but i have only been playing around with vb for a few days, the boss has got me doing some stuff for him so not a expert yet.
Can you tell me how i would get it file path through the excel object model
Thanks again
Will
MSDN Viewer
I'm no expert in the Excel object model, but it looks like the Workbook.Path property should return the location of the current Workbook.
- Steve
Brian Newer
Hi,
I'm guessing that he problem isn't the CurDir function, it's your settings in Excel.
When you open Excel, it uses the "Default file location" property to determine it's default path - it doesn't matter where you opened the document from.
CurDir (or the newer My.Computer.FileSystem,CurrentDirectory property) returns the directory where your code is executing, unless you have explicitly changed it using the FileSystem object.
If you are trying to determine the directory where the workbook was saved, you would probably need to get it's file path through the Excel object model.
Hope this helps,
Steve Hoag
Visual Basic Express
NyaRuRu
Thanks steve,
I'm definitely not an expert but thats helped and solved the problem.
The code was ThisWorkbook.Path in the end, but you got me there.
Cheers mate
Evan Mulawski
Hi,
Does the above reply solve your problem If yes then can you please click on "Mark as Answer" for the reply so that the replying member or members of forum will know that your problem is solved.
Thank you,
Bhanu.