[英]How to find the full network path of an excel file shared in a network?
我有一个支持宏的工作表,它位于我的PC上的共享位置。 此工作表用于从员工收集一些数据,位于网络中的共享位置。 它具有以下功能:当用户无法及时填写数据时,会向其发送提醒邮件。 在邮件内容中,我想将本地网络路径添加到我的Excel文件中。
我通过添加代码来实现这一目标
“You can access the tool from the location " & ThisWorkbook.FullName
在使用此代码发送邮件时,我获取此文件夹的路径为C:\\ Users \\ XYZ \\ Hello.xlsm我想发送带有IP地址的网络路径,以便用户可以直接将路径复制到运行并访问该文件。
有趣的是,如果我通过访问我的共享文件夹中的文件从其他系统发送邮件,则邮件将与网络路径一起发送。 任何人都可以帮忙吗?
我使用Excel 2007
为什么ip地址? 你不能使用计算机名。
file:\\computername\Users\XYZ\Hello.xlsm.
但说实话,我认为你正在为这种方式做一些痛苦的事情。 为什么不将HTML表单和一些PHP将数据放入MySQL中,然后将其提取到Excel或其他任何内容中?
- 编辑
这是获取计算机名的可能方法的链接。 我没有尝试过,所以我不知道它是否有效。
http://spreadsheetpage.com/index.php/tip/retrieving_the_computer_name_or_logged_in_user_name/
你的基础可能是固定的,所以我会寻求一个简单的解决方案,如:
Replace(ThisWorkbook.FullName,"C:\Users\","file:\\computername\Users\)
我部分解决了我的问题。 我使用一个函数来查找计算机名称并操纵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
缺点:如果文件位于共享文件夹中的文件夹中,则无法找到正确的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.