简体   繁体   English

如何查找网络中共享的excel文件的完整网络路径?

[英]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. 我有一个支持宏的工作表,它位于我的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. 在邮件内容中,我想将本地网络路径添加到我的Excel文件中。

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. 在使用此代码发送邮件时,我获取此文件夹的路径为C:\\ Users \\ XYZ \\ Hello.xlsm我想发送带有IP地址的网络路径,以便用户可以直接将路径复制到运行并访问该文件。

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 我使用Excel 2007

Why the ip address? 为什么ip地址? 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? 为什么不将HTML表单和一些PHP将数据放入MySQL中,然后将其提取到Excel或其他任何内容中?

--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/ 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 我使用一个函数来查找计算机名称并操纵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. 缺点:如果文件位于共享文件夹中的文件夹中,则无法找到正确的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#(WCF)-在网络共享驱动器中创建Excel文件 - C#(WCF) - Create excel file in network shared drive 当共享网络上的其他人更改文件时,如何更新Excel上的链接 - How to update links on excel when a file was changed by someone else on a shared network 如何将HTML表单数据导出到保存在共享网络驱动器上的Excel文件? - How to export HTML form data to an excel file saved on a shared network drive? 如何使用Excel VBA访问共享的网络文件夹? - How To Access Shared Network Folder Using Excel VBA? OLEDB与Excel的连接不喜欢网络共享路径 - OLEDBConnection to Excel does not like network share path 如何轻松获取您正在处理的文件的网络路径? - How to easily get network path to the file you are working on? excel 宏的完整文件路径 - Full file path of an excel macro 如何使用vba访问具有不同凭据的网络Excel文件? - How to access a network excel file with different credentials using vba? Excel找出网络中的Windows版本 - Excel to find out Windows version in network 当其他用户正在编辑(打开)Excel工作簿时,如何限制用户编辑网络共享文件夹中的Excel工作簿? - How to restrict a user from editing an Excel workbook in a network shared folder when it is being edited (open) by another user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM