Code that "knows" which button has been pressed?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello, hope someone can help.

We have a file and each row has a hyperlink in column F. Each hyperlink points to a different Word document that is relevant to that particular record.

We have had a number of occasions where the spreadsheet has gone rogue and when Excel recovers it all of the hyperlinks then point to some location on the c: drive (Appdata / Local, just a random location).

The workaround, I think, is to add a button to each cell in column F and have it open the file which will be named in column N.

So rather than have a macro for each button, is it possible to have one macro that will open the right file? So row 2 button might call C:\test1.doc whereas row 9 button might call c:\hello.doc.

Essentially, the macro needs to "know" which of the hundreds of buttons has been pressed.

Hope that makes sense, thank you for reading.
 

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.
Yes as long as you use Form buttons rather than ActiveX. In that case, Activesheet.Buttons(Application.Caller) would give you a reference to the specific button, and you can assign the same macro to all the buttons.
 
Upvote 0
Dont have hundreds of buttons. You could use for example a double click event.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

MsgBox "Row " & Target.Row

End Sub
 
Upvote 0
If the spreadsheet has a habit of "going rogue" adding hundreds of buttons is unlikely to help with the stability.

You could also consider using the =HYPERKLINK() function.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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