+ Reply to Thread
Results 1 to 8 of 8

VBA error when using "Save As" to save a copy

  1. #1
    Forum Contributor Nitro2481's Avatar
    Join Date
    09-09-2014
    Location
    Laois, Ireland
    MS-Off Ver
    2013
    Posts
    323

    VBA error when using "Save As" to save a copy

    Hi Guys,

    I have the following code in my workbook under "this_workbook"
    I have a user form where different people have different logins and when they login they have access to different sheets. I would have access to all sheets that I would not like staff to access. I cannot remember the initial problem, but sometimes when I logged out staff could see my sheets when they logged in so someone helped me with the below code so every time anyone closed the workbook all sheets are hidden first then it shuts down, this fixed the error where the person coming after me could only see the splash sheet while they logged in then only gained access to their own sheets.

    The issue I am having is, once a week just to be cautious I save a backup of this workbook on a separate drive on the computer by using "save as". (I have no access to cloud backup in work) This works fine and I "save as" worksheet 1 (backup) then I close it and all sheets hide. However when I go to open the original worksheet 1 all previous sheets are still open. I know this is because by using the "save as" the original one never got to close properly therefore the below code never kicked in.

    Any suggestions how to work around this? Now that I know it happens I always go straight back to the original open it and close it too but that's a bit of a clunky workaround


    Please Login or Register  to view this content.
    Thanks in advance

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA error when using "Save As" to save a copy

    Try using 'SaveCopyAs" instead of "SaveAs". It should leave your original workbook intact and you can then close it via normal process.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor Nitro2481's Avatar
    Join Date
    09-09-2014
    Location
    Laois, Ireland
    MS-Off Ver
    2013
    Posts
    323

    Re: VBA error when using "Save As" to save a copy

    Thanks JLGWhiz,

    I am using excel 2003, when I click on file, there is no savecopyas, just save, save as, save as workspace

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA error when using "Save As" to save a copy

    The SaveCopyAs is a VBA method. You would need a simple macro to do the job.
    Please Login or Register  to view this content.
    Example of path and file name: "C:\Temp\myXLfiles\myFilebk.xlsx"
    The code would go in the public code module1. You would need to be sure your workbook is a macro enabled workbook with the .xlsm file extension.
    Last edited by JLGWhiz; 07-20-2018 at 11:36 AM.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA error when using "Save As" to save a copy

    VBA method should still be available I believe.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  6. #6
    Forum Contributor Nitro2481's Avatar
    Join Date
    09-09-2014
    Location
    Laois, Ireland
    MS-Off Ver
    2013
    Posts
    323
    When would this code be activated and also note that some users of the spreadsheet would not have access to the drive I’d normally save it in. It’s a managers drive that I can access on any computer with my login. No one else can log into it. I expect this would cause an error

    Quote Originally Posted by JLGWhiz View Post
    The SaveCopyAs is a VBA method. You would need a simple macro to do the job.
    Please Login or Register  to view this content.
    Example of path and file name: "C:\Temp\myXLfiles\myFilebk.xlsx"
    The code would go in the public code module1. You would need to be sure your workbook is a macro enabled workbook with the .xlsm file extension.

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA error when using "Save As" to save a copy

    You would have to manually initiate the code. You can do that several ways.
    1. Press Alt + F8, click on the macro name, then click 'Run'.
    2. Use Keyboard shortcut key, assign the key by pressing Alt + F8, click Options and fill in the appropriate blocks in the dialog box.
    3. Assign it to a button by going to 'Developer', 'Insert' and clicking on command button in the 'Form Controls' tool box. When you place the button on the sheet, complete the dialog box entries.
    Last edited by JLGWhiz; 07-20-2018 at 01:25 PM.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA error when using "Save As" to save a copy

    This post deleted..
    Last edited by JLGWhiz; 07-20-2018 at 07:04 PM.

+ 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. Code only runs when a user hits "Save", not "Save As"
    By cjstewart8 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2014, 07:41 PM
  2. Replies: 4
    Last Post: 04-05-2014, 08:53 AM
  3. [SOLVED] Disable save and prevent "Do you want to save" message from prompting for read-only file
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2014, 12:29 AM
  4. Need macro to disable "Save" and "Save as" buttons
    By Anforya in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-20-2013, 01:06 PM
  5. Only "save" option in save prompt while closing excel sheet
    By rudswa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2013, 08:07 PM
  6. Replies: 0
    Last Post: 06-07-2010, 05:07 AM
  7. [SOLVED] "Subscript out of range" error for: Workbooks("Test1.xls").Save
    By Just12341234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-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