Assign macro to a button only works the first time in a workbook

Status
Not open for further replies.

S Oberlander

Board Regular
Joined
Nov 25, 2020
Messages
153
Office Version
  1. 365
Platform
  1. Windows
I have this procedure for showing details on a pivot table where a button is added and a macro is assigned to it on the new page.

It always works fine the first time and the button does what it needs to.
But when being used again on the same workbook, it seems to work fine, however when the button is clicked there is popup saying it can't access the file [containing the macro].
The weird part here is that the path listed on the popup is distorted from what is in the macro.

Note I initially tried doing this in a Private Sub Workbook_SheetBeforeDoubleClick which gave me the same issue.

Here is a screenshot of the popup and the code below it.
1634826266064.png

VBA Code:
Sub drillpivot()
On Error GoTo ex 'if the selected cell is not a value of the pivot table it will not and is not supposed to work
    Selection.ShowDetail = True 'this automatically adds a new sheet with the details of the selected value and activates the new sheet
    Range("K:K,M:N,E:E,O:Y").EntireColumn.Hidden = True
    ActiveSheet.Buttons.Add(937.5, 23.25, 114.75, 27).Select
    Selection.OnAction = "R:\Macro Data\RP Macro Wrkbk!refreshT"
    Selection.Characters.Text = "Refresh Table"
    Range("A1").Select
ex:
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Duplicate to: Beforedoubleclick code only works once

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,591
Messages
6,179,768
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