简体   繁体   中英

How to find the full network path of an excel file shared in a network?

I have a macro-enabled worksheet that resides in a shared location on my PC. This sheet, used to collect some data from employees resides in a shared location in network. It has a feature where users are sent reminder mails when they fail to fill data in time. In the mail content I like to add the local network path to my excel file.

I accomplish this by adding the code

“You can access the tool from the location " & ThisWorkbook.FullName

On sending mails using this code I get the path to this folder as C:\\Users\\XYZ\\Hello.xlsm I would like to send the network path with IP address so that users can directly copy the path into run and access the file.

Interesting thing is that if I send the mail from another system other than mine by accessing the file form my shared folder, the mail is sent with the network path. Can anyone help on this?

I use Excel 2007

Why the ip address? Couldn't you use the computer name.

file:\\computername\Users\XYZ\Hello.xlsm. 

But to be perfectly honest, I think you are setting yourself up for a some pain doing things this way. Why not an HTML form and a bit of PHP putting the data into MySQL which you can then extract into Excel or anything else?

--Edit

Here is a link to a possible method of getting the computername. I haven't tried it so I can't say if it works or not.

http://spreadsheetpage.com/index.php/tip/retrieving_the_computer_name_or_logged_in_user_name/

你的基础可能是固定的,所以我会寻求一个简单的解决方案,如:

Replace(ThisWorkbook.FullName,"C:\Users\","file:\\computername\Users\)

I partially solved my problem. I used a function to find the computer name and manipulated ThisWorkbook.Fullname

Private Declare Function GetComputerName Lib "kernel32" _
    Alias "GetComputerNameA" _
    (ByVal lpBuffer As String, nSize As Long) As Long

Function ReturnComputerName() As String
    Dim rString As String * 255, sLen As Long, tString As String
    tString = ""
    On Error Resume Next
    sLen = GetComputerName(rString, 255)
    sLen = InStr(1, rString, Chr(0))
    If sLen > 0 Then
        tString = Left(rString, sLen - 1)
    Else
        tString = rString
    End If
    On Error GoTo 0
    ReturnComputerName = UCase(Trim(tString))
End Function    


Sub GetThePath()
    If Left(ThisWorkbook.FullName, 2) <> "\\" Then
        If Sheet4.Range("B15").Value = "No" Then
            CN = "file:\\" & Evaluate("=ReturnComputerName()") & "\"
        End If
        mynames = ThisWorkbook.Path
        mynamesa = Split(mynames, "\")
        elem = UBound(mynamesa)
        mynames = mynamesa(elem)
        mynames = mynames & "\" & ThisWorkbook.Name
        mynames = CN & mynames
    ElseIf Left(ThisWorkbook.FullName, 2) = "\\" Then
        mynames = ThisWorkbook.FullName
    End If
End Sub

Demerit: Cannot find the correct path if the file is in a folder within a shared folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM