+ Reply to Thread
Results 1 to 7 of 7

Module not seeing functions in ThisWorkbook

  1. #1
    Registered User
    Join Date
    11-25-2007
    Posts
    46

    Module not seeing functions in ThisWorkbook

    I may have accidently sent my query before I was done - sorry if I did.

    The code below is in MyWorkbook, in module 2. It calls several functions (Fileopen, SummarySheetMan, Copy_Paste_to_PowerPoint) which are located in the "ThisWorksheet" code section of the same MyWorkbook. Last week this all ran fine but now it stops at the first function and says it cannot find the function (I am assuming it will not find any of the funtions). If I copy all the functions into module 2 then it works fine (all functions work). Is there some code I need to put in module 2 or in ThisWorksheet to make these functions visible / available? I would prefer to not have to copy and paste all the functions into module 2 if it can be avoided.

    Please Login or Register  to view this content.
    Below is the code in that calls the RunThisMacro which is in MyWorkbook above. This is in a different workbook (MyStartingWorkbook) and is using the Application.Run command to open MyWorkbook above and have the RunThisMacro start its work.

    Please Login or Register  to view this content.
    Not sure why this ran fine last week. I might have initiated MyStartingWorkbook from a different location. I might have had some other Excel workbooks open at the time that contained this same function. Today I only have MyStartingWorkbook open.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    The only code that should be in the ThisWorkbook and the sheet class modules is the event handling code. Everything else should go in code modules.

    Other procedures in those modules can be called from within the module, but it's bad practice. Procedures in those modules cannot be called from outside them.

  3. #3
    Registered User
    Join Date
    11-25-2007
    Posts
    46

    Thanks

    Thanks for the reply.

    So basically all my subroutines should be in modules (module 1 or module 2) and not in the "Thisworkbook" or "Sheet" modules. I think I got into this practice because when you record a macro it saves them in Thisworbook?

    Does it hurt to have them in both a module and the Thisworkbook? I have buttons with assigned macros on the worksheets. And they point to "!Thisworkbook.Macroname". If it is okay then I don't have to reprogram those buttons.

    Cam

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    ctmurray,

    Please read forum rules and the message to cross posters below and then add a link to the cross post

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    11-25-2007
    Posts
    46

    Crosspost of my question

    http://www.vbaexpress.com/forum/showthread.php?t=16976

    As requested the URL to my cross posting.

    When I started this inquiry the Excelforum was having problems. So I also posted in another site, thus cross posting. In fact today I am still having database errors. For example I cannot seem to preview this post. I hope I have used the URL link correctly, but I cannot confirm.

    Cam

  6. #6
    Registered User
    Join Date
    11-25-2007
    Posts
    46

    Thanks

    The advice to move all subroutines to modules (instead of having them in the "Thisworkbook" collection solved the problem. I ended up leaving the same subroutines in the "Thisworkbook" and just imported the new module 2 into the many workbooks.

    Amazingly, somehow, last week these macro's ran from the Thisworkbook section. I have no idea how I managed this.

    Again thanks,

    Cam

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Quote Originally Posted by ctmurray
    ...when you record a macro it saves them in Thisworbook? ...
    Record Macro saves the code in a normal module (eg. Module1) of This Workbook (with a space), not the ThisWorkbook code module of This Workbook.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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