+ Reply to Thread
Results 1 to 8 of 8

Calling Code in Another Worksheet or Module

  1. #1
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Calling Code in Another Worksheet or Module

    Hi,

    Sheet11 has a Private Sub Worksheet_activate() routine. Its job is to copy data from Sheet04.

    Sheet04 is password protected.

    Module1 has Sub ProtectOff() that will un-protect a worksheet.

    Question: How can I call ProtectOff from Private Sub Worksheet_activate() on Sheet11?

    I would most appreciate any suggestions.

    Thanks,
    tom

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Calling Code in Another Worksheet or Module

    This will call your ProtectOff procedure in another module of the same workbook.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Calling Code in Another Worksheet or Module

    Hi AlphaFrog,

    Thanks for posting. I tried calling ProtectOff from inside my _activate() routine like this:

    Please Login or Register  to view this content.
    But it did not un-protect sheet04, as desired. What can I do differently?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Calling Code in Another Worksheet or Module

    I'm guessing the ProtectOff procedure is written to work on the ActiveSheet. Wrapping it within a With code block doesn't pass that sheet to the procedure.

    You could rewrite ProtectOff to accept a worksheet argument something like this...

    Please Login or Register  to view this content.

    And then call it like this...
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Calling Code in Another Worksheet or Module

    AlphaFrog: Oops. My post above shows Sheets(04) which does not work because the editor deletes the leading zero. The real code is Sheets("INV"). I was trying to simplify.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Calling Code in Another Worksheet or Module

    Quote Originally Posted by snapfade View Post
    AlphaFrog: Oops. My post above shows Sheets(04) which does not work because the editor deletes the leading zero. The real code is Sheets("INV"). I was trying to simplify.
    My previous answer #4 still applies.

  7. #7
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Calling Code in Another Worksheet or Module

    Thanks! I will try it now!

  8. #8
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Calling Code in Another Worksheet or Module

    Thanks a bunch, AlphaFrog. It works perfectly. tom

+ 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. Excel VBA - calling a function located in a worksheet code module
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2015, 08:27 AM
  2. Sending VBA code from a Module to Code a worksheet
    By jacksocket in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2013, 08:06 PM
  3. new to vba, module or worksheet code?
    By c2q in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 07:33 PM
  4. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  5. Calling worksheet module from other module.
    By Michael Malinsky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2005, 04:50 PM
  6. Run worksheet module code from workbook module?
    By keithb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2005, 12:05 AM
  7. Create a newworksheet with VBA code and put VBA code in the new worksheet module
    By ceshelman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2005, 12:05 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