+ Reply to Thread
Results 1 to 14 of 14

Call Specific worksheet function from ThisWorkbook module

  1. #1
    Registered User
    Join Date
    07-15-2015
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    5

    Angry Call Specific worksheet function from ThisWorkbook module

    Hi!

    Am trying to run the following code from the ThisWorkbook module. However, I'm faced with the error: "Compile Error. Method or Data member not found."
    Please Login or Register  to view this content.
    It calls the code from all the sheets (other than the Settings). They have the same code as per below.
    Please Login or Register  to view this content.
    Please help. Thanks

  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: Call Specific worksheet function from ThisWorkbook module

    Try:

    Please Login or Register  to view this content.

    Late Correction:


    I should have said -

    Please Login or Register  to view this content.
    But it wouldn't have solved anything anyway
    Last edited by xladept; 07-21-2015 at 01:30 PM.
    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
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    Never mind. xladept is on it.
    Last edited by skywriter; 07-15-2015 at 11:14 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Registered User
    Join Date
    07-15-2015
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    5

    Re: Call Specific worksheet function from ThisWorkbook module

    Still the same error. The sub routine runs perfectly fine by itself when called from within the worksheet. It only faces this error when called from the ThisWorkbook module. Any help?

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    Okay, just to make sure we're on the same page.

    This sub routine.
    Please Login or Register  to view this content.
    Is event driven, it runs from the AfterSave event, which I've never used but it seems self explanatory, you save the workbook this code runs.

    Is that your understanding or are you trying to call the AfterSave sub routine by using code somewhere else in your workbook?

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    After doing some experimentation I found the following.
    Since you have defined ws as a worksheet, then as soon as you type ws. you get Intellisense. You will notice the sub routine you are trying to call is not one of your choices.
    You can call this sub routine by simply having the name on a line.
    Please Login or Register  to view this content.
    Looping through the worksheets in the code as you are doing is doing nothing for you. I suspect you think you are passing a value or something else and this is the reason for looping through the code. I see you have a variable sLastEdit, is that variable defined by each sheet somehow and you are wanting to loop the sheets to change the variable each time you call the UpdateLastUpdate routine?

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    So have a look at the workbook below.

    I have this code in ThisWorbook
    Please Login or Register  to view this content.
    This code in a standard module.

    Please Login or Register  to view this content.
    You can see in the workbook I have values in A1 on each of the three sheets and when you save the worksheet I get three message boxes all with the values from A1 in each of those sheets.
    Hopefully this will help you figure out what you need to do.

    Good Luck.
    Attached Files Attached Files
    Last edited by skywriter; 07-16-2015 at 02:27 AM.

  8. #8
    Registered User
    Join Date
    07-15-2015
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    5

    Re: Call Specific worksheet function from ThisWorkbook module

    Hey. Thanks for your help.

    Few things though, I'm trying not to write the variable to the worksheet to increase the efficiency. The real worksheets goes in excess of 100000 rows. Here is a simplified file to explain what I'm trying to do.LoveKiss431a.xlsm

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    There's three empty sheets.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Call Specific worksheet function from ThisWorkbook module

    Declare ws as Object. The base Worksheet class doesn't have the routine you are trying to call, hence the error.
    Remember what the dormouse said
    Feed your head

  11. #11
    Registered User
    Join Date
    07-15-2015
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    5

    Re: Call Specific worksheet function from ThisWorkbook module

    @romperstomper, you're a genius. I never thought about the Worksheet class.

    Sidenote: Do I have to clear the Object from memory or would it clear automatically at the end of the Sub routine?

    Thanks guys :D

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Call Specific worksheet function from ThisWorkbook module

    It will automatically clear.

  13. #13
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Call Specific worksheet function from ThisWorkbook module

    Quote Originally Posted by losekiss431a View Post
    @romperstomper, you're a genius. I never thought about the Worksheet class.

    Sidenote: Do I have to clear the Object from memory or would it clear automatically at the end of the Sub routine?


    Thanks guys :D
    I still don't know what you were doing or how you incorporated romperstomper's suggestion.

    Can you share the final code with us?

  14. #14
    Registered User
    Join Date
    07-15-2015
    Location
    Earth
    MS-Off Ver
    2013
    Posts
    5

    Re: Call Specific worksheet function from ThisWorkbook module

    @Skywriter,

    Here's the final code.
    Please Login or Register  to view this content.
    As the issue I was facing had nothing to do with any front-end UI, I left them blank. Do take a look at the named range and the VBA code. Think you'll get it Let me know if you want me to explain further.

+ 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] How can I call a Module or a sub procedure and run it automatically in current module?
    By qzqzjcjp in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2014, 11:48 AM
  2. How to call a procedure from a different module, witihin "ThisWorkbook"
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-08-2012, 09:59 AM
  3. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  4. Problem with ThisWorkbook Module
    By docnadir in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2011, 12:02 PM
  5. Using a module to call data from a different worksheet.
    By Corbet in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2011, 11:35 AM
  6. Code in 'ThisWorkbook' module in add-in?
    By karan in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-04-2009, 03:36 AM
  7. [SOLVED] Calls from sheet module to ThisWorkbook module
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2005, 11:05 AM

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