When VBA creates a hyperlink, it is using the original cell value as the name. I cant figure out how to stop it from doing this...

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
My current code looks like this:

VBA Code:
Sheets("Seatex Incident Log").Hyperlinks.Add Sheets("Seatex Incident Log").Cells(RecordRow, 29), "J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\" & Me.txtIncidentID1.Text & ".jpg"

Cell 29 on the worksheet will always have a "-" (single dash) in it (always until when, and if, it is to be replaced with a hyperlink address, that is.)

What I am left with after running the code to update the worksheet via my userform is a hyperlink that looks like this: " - "

But what I need is it to show is what the code shown above is telling it to... so in the cell it should end up looking like this:


J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\22-1150.jpg

Where the "22-1150" represents a number from the userform ("Me.txtIncidentID1") that is specific for that record.

Thoughts? Suggestions? Thanks everyone.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I think I was trying to overthink this one 🙃

It finally dawned on me that the solution was really simple:

VBA Code:
With ws
    If chkAddPic.value = True Then

        .Cells(RecordRow, 29).value = "J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\" & Me.txtIncidentID1.Text & ".jpg"

        Sheets("Seatex Incident Log").Hyperlinks.Add Sheets("Seatex Incident Log").Cells(RecordRow, 29), "J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\" & Me.txtIncidentID1.Text & ".jpg"                
    Else
    End If
End With

All that it needed was to change the cells contents from " - " to the text that I wanted the hyperlink to show, and THEN add the hyperlink. (y) (duh)
 
Upvote 0
Just to round out the discussion, a couple of other options would have been.
1) since you want the full address in the cell, instead of:
.Cells(RecordRow, 29).value = "J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\" & Me.txtIncidentID1.Text & ".jpg"
You could have just cleared the cell
.Cells(RecordRow, 29).ClearContents

2) If you did want something different you could have used the display text property.

VBA Code:
    Dim sPicName As String
    sPicName = "J:\QMS_General Facility\INCIDENT LOGS\Incident_Pictures\" & Me.txtIncidentID1.Text & ".jpg"

    ActiveSheet.Hyperlinks.Add _
        Anchor:=Sheets("Seatex Incident Log").Cells(RecordRow, "B"), _
        Address:=sPicName, _
        TextToDisplay:=sPicName
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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