[英]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.