+ Reply to Thread
Results 1 to 10 of 10

Error when calling a 'sheet macro' inside a workbook wide macro

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    35

    Error when calling a 'sheet macro' inside a workbook wide macro

    I have a 'sheet macro' named Tabname_1 which simply renames the sheet tab based upon a cell value in the sheet. (By 'sheet macro' I mean that special kind of macro you create by right clicking on the tab name and selecting 'View Code'. It only applies to the current sheet.) Now I want to run this sheet macro within another larger macro that exists in the same workbook. But when I put 'Call Tabname_1' in the main macro I get the error: 'Sub or function not defined'. I also tried simply putting Tabname_1 instead of Call Tabname_1. But I get the same error.

    Is there some special syntax to call a sheet macro within a normal macro? Thanks
    Last edited by Rhino_dance; 08-09-2016 at 12:26 AM. Reason: typos

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Hi Rhino_dance,

    Could you post your code or even better:Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-13-2012
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Here is my main macro:

    Please Login or Register  to view this content.

    And here is the 'Sheet Macro' named TabName_1 that I am trying to run inside my main macro:

    Please Login or Register  to view this content.
    Thanks.

    Moderator Note: I have added code tags to your VBA. Please read the rules that you agreed to when you joined this forum and adhere to them in the future.
    Last edited by alansidman; 08-09-2016 at 09:07 PM.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    TabName_1() needs to be in a standard, not a sheet, module - is it?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,120

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Try
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Registered User
    Join Date
    06-13-2012
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Thanks that worked.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    You're welcome and thanks for the rep!

    I assume that Trevor's worked as well

  8. #8
    Registered User
    Join Date
    06-13-2012
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Yes, I used Trevor's answer. I appreciate everyone's input and help on this. -John

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    Well the only problem I anticipate with Trevor's answer is that the host sheet must be named Sheet1

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,120

    Re: Error when calling a 'sheet macro' inside a workbook wide macro

    You're welcome. Thanks for the rep.

    xladept is quite right. My solution is using the Code Name for Sheet1 which is, by default, Sheet1. The end user cannot change that from the worksheet ... but you or they could in the VB Editor. Unlikely though.

    Strictly speaking, although your routine is only used in relation to Sheet1/Tab1, it is NOT a worksheet macro; it is not an Event handler, or related to a control, etc. So, by rights, it should be in a Standard Module ... then everything can find it.


    To create a Standard Module:
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.How to install your new code

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro only runs from inside sheet not from another workbook/module
    By gabbana in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-30-2015, 06:40 AM
  2. [SOLVED] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  3. [SOLVED] Calling a macro inside another macro
    By MikeMeerkat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2015, 05:30 AM
  4. Error when calling macro
    By jamer02 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-18-2013, 06:33 PM
  5. Help!! - Subscript Out of Range - Error while calling a workbook frmm another sheet..
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-29-2012, 12:53 PM
  6. Calling macro in another workbook
    By scabral in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:03 PM
  7. Calling Macro From Different Workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-23-2008, 07:03 PM

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