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