dawn Master Poster
Joined: 26 Jun 2004 Posts: 311 Location: Mishawaka, IN
|
Posted: Fri Dec 05, 2008 11:08 am Post subject: Code to convert UNC to URL |
|
|
Q: I've got a number of users who publish data to the intranet by copying it
onto a server then making links to it.
I'd like to make a script for the people who are finding it a little
confusing to convert the UNC of the file into a URL.
Here's an example:
UNC: \\web1a\PIBReports\BCA\Admin_Reports\User_List.pdf
URL: http://web1/pibreports/bca/admin_reports/user_list.pdf
A:
Code: | -------------------------------------------------------------
on error resume next
Function GetUrlFromUnc(Unc)
Const BASE_URL = "http://web1/"
Const BASE_FOLDER = "pibreports"
Dim iPos
iPos = InStr(1, Unc, BASE_FOLDER, vbTextCompare)
If iPos > 0 Then
Dim sSubPath
sSubPath = Mid(Unc, iPos)
sSubPath = Replace(sSubPath, "\", "/")
sSubPath = Escape(sSubPath)
GetUrlFromUnc = lcase(BASE_URL & sSubPath)
Else
'Invalid Folder
GetUrlFromUnc = ""
End If
End Function
AppCap = "Convert File Path to HyperLink"
strCopy = GetUrlFromUnc(InputBox("Please enter the file
path",AppCap,"\\web1a\PIBReports\"))
If strCopy <> "" Then
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", strCopy
objIE.Quit
MsgBox "The HyperLink (URL) to your file has been copied to the clipboard,
please use the Paste command on the Edit menu or 'CTRL+V' to use it." +
Chr(10) + strCopy, 64, AppCap
Else
End If
'-------------------------------------------------------------
|
_________________ Dawn Mitchell
Manufacturing Information Solutions
www.mis-group.com |
|