Current Directory

hawley

Board Regular
Joined
Apr 7, 2002
Messages
197
Does anyone know how to see what the current directory is? What I am trying to do is see which directory the user opened the excel sheet from. The problem is I don't want the drive letter but the server name. I have tried using:
Application.StartupPath
ThisWorkbook.Path
There are a few more but they all give me the drive letter, T:Test, and what I want is the server name, \serverTest. Help!!

Thanks--
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
When I use CurDir it gives me the drive letter and that is not what I want.
Thanks for the suggestion though.
 
Upvote 0
On 2002-05-31 06:04, hawley wrote:
When I use CurDir it gives me the drive letter and that is not what I want.
Thanks for the suggestion though.

You want the UNC Dir....your'll need to
use some API....if you want then repost.
 
Upvote 0
In a cell try =Cell("filename",A1)

Any cell but A1, if you put this function in A1 change the reference to any other cell.

This gives you the Drive/Path/File/Sheet of the current open file. Which should be the current directory, but may not allways be so. JSW
 
Upvote 0
On 2002-05-31 19:25, Joe Was wrote:
In a cell try =Cell("filename",A1)

Any cell but A1, if you put this function in A1 change the reference to any other cell.

This gives you the Drive/Path/File/Sheet of the current open file. Which should be the current directory, but may not allways be so. JSW

Hi Joe I think he is After The UNC drive
for a particular Dive letter eg Y: UNC convention may be \servershared etc.
You can get this via a few API's
 
Upvote 0
Ivan could you give me an example of that API stuff. That is what I want.

Thanks-
 
Upvote 0
On 2002-05-31 19:25, Joe Was wrote:
In a cell try =Cell("filename",A1)

Any cell but A1, if you put this function in A1 change the reference to any other cell.

This gives you the Drive/Path/File/Sheet of the current open file. Which should be the current directory, but may not allways be so. JSW

Joe,

also =INFO("directory") will give just the drive and path, if you don't want the file and sheet info (saves a bit of "finding" and "replacing" formulae)

Chris
:)
 
Upvote 0
Here's an article that may help ...
TITLE
:VBA: Sample Code to Return the UNC Path of a Network Drive (Q160529)


SUMMARY
This article describes how to use a Microsoft Visual Basic for Applications Sub procedure (or macro) and a Windows application programming interface (API) call to return the universal naming convention (UNC) path for a mapped network drive.

URL:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q160529

CODE
Code:
 ' 32-bit Function version.
   ' Enter this declaration on a single line.
   Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
      "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
      lpszRemoteName As String, lSize As Long) As Long

   ' 32-bit declarations:
   Dim lpszRemoteName As String
   Dim lSize As Long

   ' Use for the return value of WNetGetConnection() API.
   Const NO_ERROR As Long = 0

   ' The size used for the string buffer. Adjust this if you
   ' need a larger buffer.
   Const lBUFFER_SIZE As Long = 255

   Sub GetNetPath()

      ' Prompt the user to type the mapped drive letter.
      DriveLetter = UCase(InputBox("Enter Drive Letter of Your Network" & _
         "Connection." & Chr(10) & "i.e. F (do not enter a colon)"))

      ' Add a colon to the drive letter entered.
      DriveLetter = DriveLetter & ":"

      ' Specifies the size in charaters of the buffer.
      cbRemoteName = lBUFFER_SIZE

      ' Prepare a string variable by padding spaces.
      lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)

      ' Return the UNC path (ServerShare).
      lStatus& = WNetGetConnection32(DriveLetter, lpszRemoteName, _
         cbRemoteName)

      ' Check to see if WNetGetConnection() succeeded. WNetGetConnection()
      ' returns 0 (NO_ERROR) if it succesfully retrieves the UNC path.
      If lStatus& = NO_ERROR Then

         ' Display the UNC path.
          MsgBox lpszRemoteName, vbInformation

      Else
         ' Unable to obtain the UNC path.
         MsgBox "Unable to obtain the UNC path.", vbInformation
      End If

   End Sub
This message was edited by Nimrod on 2002-06-03 17:19
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top