Spreadsheet 123 Excel 2003, XP, 2000, 97 FAQs: Extract hyperlink to Files

Extract hyperlink address (files and web addresses) in Excel 2003/XP/2000/97.

Question:  I have an Excel spreadsheet that contains hyperlink addresses to files. I tried extracting the hyperlink address for these files, however I'm not getting the complete Address. The complete Address should be:


C:\My Documents\Past Projects\Centennial\Program Status Report.xls


But I only get:


\..\..\Past Projects\Centennial\Program Status Report.xls


Is there a way to always get the complete hyperlink address?




Answer:  Below are two functions that you can include in your spreadsheet to extract the complete hyperlink address for either a file or a web address.


Function HyperLinkText(pRange As Range) As String

Dim ST1      As String
Dim ST2      As String
Dim LPath    As String
Dim ST1Local As String

If pRange.Hyperlinks.Count = 0 Then
  Exit Function
End If

LPath = ThisWorkbook.FullName

ST1 = pRange.Hyperlinks(1).Address
ST2 = pRange.Hyperlinks(1).SubAddress

If Mid(ST1, 1, 15) = "..\..\..\..\..\" Then
  ST1Local = ReturnPath(LPath, 5) & Mid(ST1, 15)
ElseIf Mid(ST1, 1, 12) = "..\..\..\..\" Then
  ST1Local = ReturnPath(LPath, 4) & Mid(ST1, 12)
ElseIf Mid(ST1, 1, 9) = "..\..\..\" Then
  ST1Local = ReturnPath(LPath, 3) & Mid(ST1, 9)
ElseIf Mid(ST1, 1, 6) = "..\..\" Then
  ST1Local = ReturnPath(LPath, 2) & Mid(ST1, 6)
ElseIf Mid(ST1, 1, 3) = "..\" Then
  ST1Local = ReturnPath(LPath, 1) & Mid(ST1, 3)
Else
  ST1Local = ST1
End If
 
If ST2 <> "" Then
  ST1Local = "[" & ST1Local & "]" & ST2
End If
 
HyperLinkText = ST1Local

End Function


Function ReturnPath(pAppPath As String, pCount As Integer) As String

Dim LPos    As Integer
Dim LTotal   As Integer
Dim LLength As Integer


LTotal = 0
LLength = Len(pAppPath)


Do Until LTotal = pCount + 1
   If Mid(pAppPath, LLength, 1) = "\" Then
      LTotal = LTotal + 1
   End If
   LLength = LLength - 1
Loop


ReturnPath = Mid(pAppPath, 1, LLength)

End Function


Then you can reference these new functions in your spreadsheet.
For example in cell B1, you could enter the following:

=HyperLinkText(A1)

Suggested Reading

Spreadsheet News



Forum


Meet advanced users of MS Excel and Spreadsheet and do not be shy to ask your question.


Book Shop


Visit our busy book shop, were you can find latest books for beginners as well as advanced users of excel and similar programs.



Software Library




Excel & Spreadsheet Online Tutorials




Spreadsheet123
Home | About Us | Our Services | Software | Excel Templates | Excel Tutorials | Useful Links | Site Map | Contact Us
Bookmark this PageBookmark this Page

Link To Us
Home
About Us

Book Shop

Excel
Excel Tutorials
Financial Modeling
Excel Templates

Excel Tutorials

Excel Basic Tutorial
Excel Tech on Net
MS Excel Tutorials and Projects
MS Excel Spreadsheet Tutorial
How to Decide What Chart Type to Use
How To Merge Cells in Excel
Excel - Printing Effectively from Excel
Using Excel Functions and Creating Formulas

Excel Templates

Corporate finance spreadsheets
Valuation Inputs Spreadsheets
Big-picture valuation spreadsheets
Focused valuation spreadsheets
Financial Service firms
Troubled firms
Private companies
Young and high-growth firms
Multiples
Valuation in Acquisitions
Valuation of other assets
Value Enhancement Spreadsheets
Basic option pricing models
Real option models in corporate finance
Real option models in valuation
Hotel & Restaurant Management Spreadsheets
Real Estate & Mortgage Excel Spreadsheets
Excel Personal Budget Spreadsheets
More Spreadsheets

Software Library

Accounting Software
Small Business Software
Tax Calculating Software
Auditing Software
Excel Add-Ins
Property Management Software
Payroll Software
Spreadsheet Software

Contact Us
Useful Links
Our Services
Site Map