Beforedoubleclick code only works once

S Oberlander

Board Regular
Joined
Nov 25, 2020
Messages
147
Office Version
  1. 365
Platform
  1. Windows
I have the below code to work on a pivot table, the code works fine the first time I use it in a workbook.
When I use it a second time the OnAction is not getting assigned properly and I get this popup when I try to use the command button.

1634754265299.png


VBA Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    'On Error GoTo ex
    Selection.ShowDetail = True
    Range("K:K,M:N,E:E,O:Y").EntireColumn.Hidden = True
    ct = Range("F2")
    If Evaluate("isref('" & ct & "'!A1)") Then
      Application.DisplayAlerts = False
      Sheets(ct).Delete
      Application.DisplayAlerts = True
    End If
    ActiveSheet.Name = ct
    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
 
I think your problem might be that this statement

VBA Code:
     Selection.OnAction  = "R:\Macro Data\RP Macro Wrkbk!refreshT"

is in error, and should be

VBA Code:
  Selection.OnAction =  "R:\Macro Data\RP Macro Wrkbk.xlsm!refreshT"
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I think your problem might be that this statement
Right, that is where the problem is
however first of all, its xlsb, and I tried it already
the issue is that it is somehow inserting a "1" after the "R"
1634835738257.png
 
Upvote 0
Ah. You were expecting a mind reader. Sorry to disappoint. Good luck with your problem.
Not really I was just saying that I tried that already and it happened to have been with xlsb....
What I really need to know is how the 'R:\ becomes 'R1:\
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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