hyperlink value vs. displayed text

Newblet

New Member
Joined
Apr 13, 2011
Messages
2
I am trying to create an asset tracking sheet that includes hyperlinks to photos of the assets being tracked. The user stores a .jpg of the asset in one specific filefolder before getting into the tracking sheet. I have a userform with a button that takes the user to the filefolder where all of our photos are stored. They then pick the appropriate photo. Doing so returns the whole UNC as a text string back to a textbox on the form. When another button is clicked, the text in the textbox, including the whole UNC for the file location, is forwarded to a spreadsheet as a hyperlink. The spreadsheet displays the whole UNC. I'd like to be able to have the hyperlink work but only display "x.jpg" instead of the whole UNC.

What do I need to add or change to do that?

So far, the button code is:

Private Sub cmdHyper_Click()
ChDrive "C"
ChDir "C:\Documents and Settings\me\Desktop\Safety\Asset_Photos"
Dim jpgName$, arr
jpgName$ = Application.GetOpenFilename(FileFilter:="All Files,*.jpg", Title:="Look for .jpg file")
arr = Split(jpgName$, "\")
Me.txtHyper.Value = jpgName$
End Sub

The code that populates the spreadsheet with the hyperlink is:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("AssetByDist")
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Formula = "=Hyperlink(""" & Me.txtHyper.Value & """)"
Me.txtHyper.Value = ""
Me.txtHyper.SetFocus
End Sub
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you were to move your variable declarations to the head of your module you could make use of both:

Code:
Dim jpgName$, arr

Private Sub cmdHyper_Click()
    ChDrive "C"
    ChDir "C:\Documents and Settings\me\Desktop\Safety\Asset_Photos"
    jpgName$ = Application.GetOpenFilename(FileFilter:="All Files,*.jpg", Title:="Look for .jpg file")
    arr = Split(jpgName$, "\")
    Me.txtHyper.Value = jpgName$
End Sub

Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("AssetByDist")
    iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    ws.Cells(iRow, 1).Formula = "=Hyperlink(""" & jpgName$ & """,""" & arr(UBound(arr)) & """)"
    Me.txtHyper.Value = ""
    Me.txtHyper.SetFocus
    Set ws = Nothing
End Sub

In terms of Variable scope see: http://support.microsoft.com/kb/141693
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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