+ Reply to Thread
Results 1 to 11 of 11

"Sub or Function not Defined" error -- cannot determine cause

  1. #1
    Registered User
    Join Date
    09-14-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    "Sub or Function not Defined" error -- cannot determine cause

    Hello,

    This is my first post so please forgive me if I am doing anything wrong. Thanks in advance for your help.

    I have multiple macros in two different workbooks, and a "Master" macro which is intended to switch back and forth between activating the two books, calling subs in each. It won't even get past the first few lines:

    Please Login or Register  to view this content.
    The Master is stored in "Blank Template with Macros.xlsm" which is the active book when Master is run. When I try to run it, I get a "Sub or Function not Defined" error and the line containing Call Create_Defects_Raw_Data_Pivot is highlighted. The workbook "Weekly Feedback Raw Data.xlsm" contains the create pivot macro. Here is the code for the create pivot macro:

    Please Login or Register  to view this content.
    This sub works fine when I run it from the feedback workbook. Shouldn't I be able to call the Create_Defects_Raw_Data_Pivot sub once the "Weekly Feedback Raw Data.xlsm" book is activated? Am I wrong in assuming that a public sub should be accessible if it is in the active workbook?

    Please let me know if you need more info.

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Try changing

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Registered User
    Join Date
    09-14-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Thanks for your quick reply -- I actually tried this already. I get the run-time error 1004:

    Cannot run the macro 'Weekly Feedback Raw Data.xlsm!Create_Defects_Raw_Data_Pivot'. The macro may not be available in this workbook or all macros may be disabled.

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Open Weekly Feedback Raw Data.xlsm manually and enable the macros manually then try running

    Please Login or Register  to view this content.
    from the other workbook.

    Does it run?
    Last edited by WasWodge; 09-25-2012 at 02:12 PM.

  5. #5
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Try
    Please Login or Register  to view this content.
    and see what happens.

  6. #6
    Registered User
    Join Date
    09-14-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: "Sub or Function not Defined" error -- cannot determine cause

    I changed the trust center settings to enable all macros in Weekly Feedback Raw Data, but running the test macro gave me the same 1004 error.

  7. #7
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    See the last post I made as you were posting and try that.

  8. #8
    Registered User
    Join Date
    09-14-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Worked that time -- thank you so much!!

    So would you recommend calling subs this way any time I run a macro that calls subs in different workbooks? Do you have any idea why activating the workbook was not sufficient?

  9. #9
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Do you have any idea why activating the workbook was not sufficient?
    Activating the workbook is literally just that, you still need to tell the code exactly where to look in the same way you have to name the sheet if you want code to run on a specific sheet.

    By the way the reason you were struggling is because there are spaces in your workbook name and so you needed the 2 extra '

  10. #10
    Registered User
    Join Date
    09-14-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: "Sub or Function not Defined" error -- cannot determine cause

    Very good to know and thank you again.

  11. #11
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: "Sub or Function not Defined" error -- cannot determine cause

    No problem, remember to mark the thread as solved if you are satisfied with the answer.

    To mark as solved

    Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes.

+ 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