+ Reply to Thread
Results 1 to 9 of 9

Syntax to call Public Macro

  1. #1
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Syntax to call Public Macro

    I am Having trouble calling an macro that is not in the module that is calling it. I thought that all I had to do was label the Macro as Public instead of private, but it is not working. If I copy and Paste the Macro code into the module that is calling it, everything works just fine, but this is making it difficult to keep things organized. i know there has to be a way to do this, any help would be great!
    I am currently just using the CALL command.
    Please Login or Register  to view this content.
    Thanks in advance for your help!
    Last edited by TheNewGuy; 07-08-2009 at 09:18 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Syntax to call Public Macro

    Is MyMacroModule2 in a normal module, or in a worksheet or ThisWorkbook module? If it's either of the last two, you would need to prefix it with the sheet name or ThisWorkbook as it is effectively a public method of those objects. I suspect it should simply be moved to a normal module though.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Syntax to call Public Macro

    MyMacroModule2 is in a normal module, and MyMacroModule1 is located in the code for a userform. If I copy the Macro located in the normal module into the userform code it works just fine.
    If I debug it the error it gives is;
    Expected variable or procedure, not module.
    But I don't know what that means.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Syntax to call Public Macro

    Do your module and sub have the same name? (they shouldn't really)

  5. #5
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Syntax to call Public Macro

    Yes! They Did have the same name, you are right! I changed the name of the sub, and it works! Thank you for your help.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Syntax to call Public Macro

    No problem. For the record, you could have used:
    Please Login or Register  to view this content.
    to work around it, but it's not good practice to use the same name for both a routine and its container, IMO.

  7. #7
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Syntax to call Public Macro

    Thank you. So just for the record is the syntax,
    Please Login or Register  to view this content.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Syntax to call Public Macro

    Yes, though Call is optional, as is the module name if the macro name is unique within the project.

  9. #9
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Syntax to call Public Macro

    OK thank you for the clarification! That is helpful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1