How do I GetCurrentDirectory in Excel?

  • Thread starter Thread starter Thunderbolt2000
  • Start date Start date
T

Thunderbolt2000

I need to retrieve the current drive letter to use in my Excel spreadsheet,
how do I retrieve it?
 
Hi Thunderbolt

if you want to have the drive letter (only the letter) you could use
following:
=LEFT(CELL("filename",A1),1)
otherwise to get the whole path, just use the cell function i used.

hth
Carlo
 
carlo said:
=LEFT(CELL("filename",A1),1)

That returns the drive letter of the workbook name, which is not necessarily
the drive of the current working directory. Moreover, it is possible, though
not at all likely, that the drive letter may have two characters (if you
have a LOT of partitions and/or mapped drives).

Instead, use code like the following:

Function CurrentDrive() As String
Application.Volatile True
CurrentDrive = Split(CurDir, ":")(0)
End Function

You can then call this from a worksheet cell with

=CurrentDrive()

--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



Hi Thunderbolt

if you want to have the drive letter (only the letter) you could use
following:
=LEFT(CELL("filename",A1),1)
otherwise to get the whole path, just use the cell function i used.

hth
Carlo
 

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

Back
Top