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
147
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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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