Getting Hyperlink Address - Excel 2003 vba

Pm1995

New Member
Joined
Dec 15, 2011
Messages
25
Hi all,

Please Help.
I am trying to retrieve the address (file path) from a Hyperlink in a cell using vba.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
try this code..
Code:
cellAddress = Replace(Range("A1").Hyperlinks(1).Address, "mailto:", "")
 
Upvote 0
it should give your the full path with filename.. Create a hyperlink on A1 then run this code, it would show you the full path in a message box and will also update the same path at B1..

Code:
Sub GetCellAddress()
    cellAddress = Replace(Range("A1").Hyperlinks(1).Address, "mailto:", "")
    MsgBox cellAddress
    Cells(1, 2) = cellAddress
End Sub
 
Upvote 0
I can see what has happened.
When the hyperlink is created the address field shows the full path.
When the workbook is saved the field name becaomes just the file name.

Do you know how I can fix this?
 
Upvote 0
Try Formula below

=fnUNCPath(LEFT(INFO("directory"),1))

Copy and paste Custom Funtion in Macro Module

Code:
 '// 32-bit Function version.
 '// Note:
Declare Function WNetGetConnection32 _
Lib "mpr.dll" _
Alias "WNetGetConnectionA" ( _
ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
lSize As Long) _
As Long
 
 '// 32-bit declarations:
Dim lpszRemoteName As String
Dim lSize As Long
 
 '// Use for the return value of WNetGetConnection() API.
Const NO_ERROR As Long = 0
 
 '// The size used for the string buffer. Adjust this if you
 '// need a larger buffer.
Const lBUFFER_SIZE As Long = 1052
 
Function fnUNCPath(strDriveLetter As String) As String
     '// Takes specified Local Drive Letter
     '// eg E,D,H Etc and converts to UNC
     
    Dim cbRemoteName As Long
    Dim lStatus As Long
     
     '// Add a colon to the drive letter entered.
    strDriveLetter = Left(strDriveLetter, 1) & ":"
     
     '// Specifies the size in charaters of the buffer.
    cbRemoteName = lBUFFER_SIZE
     
     '// Prepare a string variable by padding spaces.
    lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)
     
     '// Return the UNC path (eg.\\Server\Share).
    lStatus = WNetGetConnection32( _
    strDriveLetter, _
    lpszRemoteName, _
    cbRemoteName)
     
     '// Has WNetGetConnection() succeeded.
     '// WNetGetConnection()returns 0 (NO_ERROR)
     '// if it succesfully retrieves the UNC path.
    If lStatus = NO_ERROR Then
         '// Get UNC path.
        fnUNCPath = lpszRemoteName
    Else
         '// Unable to obtain the UNC path.
        fnUNCPath = "NO UNC path"
    End If
     
End Function

Does it help?

Biz
 
Upvote 0
Thanks Biz,

My problem is not converting a path with a drive letter to a UNC or visa versa.

For some reason only the filename is returned rather than the full path (unc or other). I can't seem to work out why.
 
Upvote 0
I read other threads with similar problem with UNC.. Got this solution, try it..

In Excel go to Tools> Options> General> Web Options> Files, un-check "Update links on save" ..
 
Upvote 0
Glad to know that it was of help.. yes that match made so much of exitment in the last 10 overs..
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,464
Members
453,044
Latest member
rgbenson1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top