• Right-click menu running code twice (Excel 2003 SP1)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Right-click menu running code twice (Excel 2003 SP1)

    Author
    Topic
    #440455

    I have a spreadsheet which needs 2 extra options on the “Cell” shortcut menu : “New Movement” and “Edit Movement”. They are visible when the appropriate sheet and workbook is active, and hidden when not.

    The problem is that when clicked these options seem to be running the function in the OnAction property twice. I have attached a very cutdown version of the sheet

    Viewing 1 reply thread
    Author
    Replies
    • #1055237

      Change the .OnAction statements to:
      .OnAction = "NewMovement"
      rather than:
      .OnAction = "=NewMovement()"
      and similarly for EditMovement.
      Why are you using functions rather than subroutines?

      • #1055241

        Rory

        Thank you very much for that advice which solves the problem.

        I was using functions because I thought you had to use them – at least, I think you have to in Access anyway. I have now changed them to subs.

        I’m just puzzled why the ‘=’ and the ‘()’ make the code run twice.

        Thanks again

        Nick

        • #1055244

          Honestly, I have no idea why. Perhaps it tries to evaluate it as a formula, thereby calling the code, then runs it as an OnAction as normal. I guess MS never expected to encounter an = sign in the OnAction property. shrug

      • #1055243

        I’ve just found out why I should have been using functions – it is because they do not show up when the user clicks Tools/Macros/Macros.. whereas the subs do, and that is not desirable for us.

        • #1055245

          Just declare the subs as Private, and they won’t appear in the macro list.

    • #1055240

      Perhaps it’s because your OnAction for the menu item is a Function rather than a Sub.

      zeddy

    Viewing 1 reply thread
    Reply To: Right-click menu running code twice (Excel 2003 SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: