Why don't VBA examples from the Help always work?

Brian

Board Regular
Joined
Apr 24, 2002
Messages
113
Direct from the excel help:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, ByVal Cancel As Boolean)
Cancel = True
End Sub

I placed this in "ThisWorkbook" but I get the error: "Compile Error: Event procedure declaration does not match description of event having the same name."

Similar stuff happens a lot when I try to use examples from the help, there is often something that needs to be adjusted. Is there some global problem that I'm not catching, or is it simply isolated mistakes in the Help files?

What I want to do:
I added an item to the cell shortcut menu, but it is only applicable on one sheet of one workbook. So I need some event that will disable it if any other sheet or workbook is right-clicked.

Regards,

Brian

Ideally,
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
copy that macro. then right click on the worksheet tab you want the code used in.
select view code.
and now paste it in there.
 
Upvote 0
On 2002-05-05 18:14, Brian wrote:
Direct from the excel help:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, ByVal Cancel As Boolean)
Cancel = True
End Sub

I placed this in "ThisWorkbook" but I get the error: "Compile Error: Event procedure declaration does not match description of event having the same name."

Similar stuff happens a lot when I try to use examples from the help, there is often something that needs to be adjusted. Is there some global problem that I'm not catching, or is it simply isolated mistakes in the Help files?

What I want to do:
I added an item to the cell shortcut menu, but it is only applicable on one sheet of one workbook. So I need some event that will disable it if any other sheet or workbook is right-clicked.

Regards,

Brian

Ideally,

The byVal reference for the cancel is wrong
should be;

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
End Sub

If only one sheet then use the sheets event
code eg

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

End Sub
 
Upvote 0
Actually, that's an interesting question for the topic. Why are the VBA examples so poorly defined and varaibles are declared as variants mostly for convenience. Is there any particular reason, or are these people just like everyone else? You know, knock something up quick and move on to the next topic.
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,146
Members
448,948
Latest member
spamiki

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