GetOpenFilename - Full Network Location

emmiewoo

New Member
Joined
Sep 24, 2009
Messages
5
Hi,

I have a macro that returns the file path of a document (see below).

Is it possible to return the full network location rather than the drive letter?

e.g. \\mna5dg\ewok\reports
instead of
K:\reports

Cheers

Sub getfilename()
'This macro is used in the form to get the filename
Dim fn
Range("File_Path").Clear
fn = Application.GetOpenFilename(, , "Find File")
Range("File_Path").Select
ActiveCell = fn
Calculate

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about

Code:
Private Declare PtrSafe Function WNetGetConnectionA Lib "mpr.dll" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long

Sub GetFileName()

    Dim FilePath As Variant
    Dim FullFilePath As String, PartFilePath As String, Buffer As String
    Dim ReturnValue As Long
    
    FilePath = Application.GetOpenFilename(, , "Find File")
    
    If FilePath <> "False" Then
    
        If Mid$(FilePath, 2, 1) = ":" Then
            DriveLetter = Left$(FilePath, 2)
            PartFilePath = Replace$(FilePath, DriveLetter, "")
            Buffer = String$(256, "^")
            ReturnValue = WNetGetConnectionA(DriveLetter, Buffer, 256)
            FullFilePath = WorksheetFunction.Trim(Left$(Buffer, InStr(Buffer, "^") - 1)) & PartFilePath
        Else
            FullFilePath = FilePath
        End If
        
        MsgBox FullFilePath
        
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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