+ Reply to Thread
Results 1 to 6 of 6

Execute code on exit

  1. #1
    Registered User
    Join Date
    02-14-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Execute code on exit

    In a shared workbook, I have the following macro that runs perfectly, linked to a button on a ribbon. However, if the same code is inserted into the VBA Workbook BeforeClose window, I get the following message, "The command could not be completed by using the range specified. Select a single cell within the range and try the command again." The macro stops on the 'Selection.AutoFilter' function.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Execute code on exit

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-14-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Execute code on exit

    Hello John and thank you for your input. Unfortunately, this created a different issue. I now get a message because the worksheet is protected. If I leave it unprotected, the pasted data is of the underlying formulas, not the resultant data. The script stops at the first ActiveSheet.Paste line.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Execute code on exit

    OK. I just ran a quick test on some dummy data I made up. Thought what I did might be the issue. Didn't know your sheet was protected.

  5. #5
    Registered User
    Join Date
    02-14-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Execute code on exit

    I apologize for leaving that bit of out my initial post. Hopefully, there won't be any other surprises.

  6. #6
    Registered User
    Join Date
    02-14-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Execute code on exit

    Still no resolution. Looks like I may have to live with the button function instead of having the macro execute automatically on exiting the program.

+ 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. Execute email notification from sheet while unlocking sheet and then protect on exit
    By dillkeva in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2013, 06:24 AM
  2. Trim code to exit code if cell is empty
    By excellenthelp in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-23-2013, 12:08 PM
  3. [SOLVED] Code won't execute
    By ccpsc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-03-2012, 06:28 PM
  4. Command line for open excel, insert a sheet, execute a macro, save file exit?
    By uschxc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2012, 12:28 PM
  5. Code won't execute...
    By Dolemite in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2005, 02:22 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