Auto Update Macro when duplicating worksheet

paulm88

New Member
Joined
Jun 13, 2017
Messages
15
I have a macro on Sheet1(Sheet1.OpenCreative) assigned to an object that is referencing a cell with a dynamic hyperlink. When I duplicate this sheet, i would like the macro in sheet 2 to automatically change to Sheet2.OpenCreative. Is this possible? Macro code below:

Sub OpenCreative()
URL = Range("A62").Text
Shell "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe " & URL, vbNormalNoFocus
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
1. BOTH procedures below are in Sheet1 's sheet module
Code:
Sub RunOpenCreative()
    Call OpenCreative
End Sub

Sub OpenCreative()
    URL = Range("A62").Text
    Shell "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe " & URL, vbNormalNoFocus
End Sub

2. Replicate Sheet1 (right click on sheet tab \ Move or COPY ..etc)

3. BOTH procedures are also in replicated sheet and RunOpenCreative in the NEW sheet refers to OpenCreative in the NEW sheet

Is that what you are wanting to do?
 
Upvote 0
Thanks for your response. Unfortunately, this doesn't seem to be working for me, as the object in sheet2 still opens the location of the URL in sheet1. Therefore, I have to manually assign the new macro to the sheet2 object, which is what i'm trying to avoid.

1. BOTH procedures below are in Sheet1 's sheet module
Code:
Sub RunOpenCreative()
    Call OpenCreative
End Sub

Sub OpenCreative()
    URL = Range("A62").Text
    Shell "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe " & URL, vbNormalNoFocus
End Sub

2. Replicate Sheet1 (right click on sheet tab \ Move or COPY ..etc)

3. BOTH procedures are also in replicated sheet and RunOpenCreative in the NEW sheet refers to OpenCreative in the NEW sheet

Is that what you are wanting to do?
 
Upvote 0
It would help if you told us what the "object" is.
Different objects behave differently.
By default, an active-x command button sitting on sheet1 which is "replicated" would do what you want on sheet2 because the code sits in the sheet module.
Which object are you using?
 
Upvote 0
Apologies Yongle, it turned out the object was an image rather than an Active X control...

Resolved this now!

Thanks for your help.

It would help if you told us what the "object" is.
Different objects behave differently.
By default, an active-x command button sitting on sheet1 which is "replicated" would do what you want on sheet2 because the code sits in the sheet module.
Which object are you using?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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