Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6584001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:28:58+00:00 2026-05-25T16:28:58+00:00

I have a macro that modifies the workbook it is executed in and I

  • 0

I have a macro that modifies the workbook it is executed in and I want that macro to save a copy of the workbook to a location (preferably specified by the user), revoke all changes to the workbook (so it’s in its original state again) and close the workbook.

Unfortunately I can’t find any input on the revoking and closing part… Saving a copy is pretty easy, but how to do the rest of those things?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:28:59+00:00Added an answer on May 25, 2026 at 4:28 pm

    I would agree with most of brettdj’s response (especially that you should save the file first). However, the BrowseForFolder function is unnecessary. Instead you can use the built-in Windows folder browser in post-2002 versions of Excel

    Sub Example()
    
    Dim strFolder as String
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    ThisWorkbook.Save
    
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
        If .SelectedItems.Count = 1 Then 
        strFolder = .SelectedItems(1)
        Else
        'Quit/Show message asking to specify location
        End If
    End With
    
    'Do everything else
    
    ThisWorkbook.SaveAs strFolder & "\" & ThisWorkbook.Name
    ThisWorkbook.Close (False)
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    End Sub
    

    The (False) on closing the workbook is short for SaveChanges:=False, and may remove the need to switch off alerts

    Also, if you wish to make the changes to a different workbook to the one containing the code, you may need help using multiple Excel files. The main lesson would be that you can substitute ActiveWorkbook for ThisWorkbook, or define the workbook upon opening

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel 2003 workbook that contains a macro to copy certain of
I have an access macro, that I want to run automatically from a batch
Specifically, I have an XSLT macro that modifies some content. I have this in
I have a macro that goes through a directory and looks at all its
I want to have a macro dbtest that can be used like this: (dbtest
I have : Macro named "process" that does all the processing work for my
I have an Excel macro that is copying all of the information from a
I want to have a C preprocessor macro that knows the number of instantiations/macro
I have a macro that I wrote to just help me with my unit
I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.