Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

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

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Posts
    113
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default

    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,

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.

  3. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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






    Kind Regards,
    Ivan F Moala From the City of Sails

  4. #4
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •