+ Reply to Thread
Results 1 to 5 of 5

Save as Script

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Save as Script

    Hello All,

    I have 2 Workbooks which use the same code listed below to save each Workbook. The issue is, the below code will not work when both Workbooks are open. I am receiving the following error:

    Run-Tim error '1004':

    You cannot save this workbook with the same name as another open workbook or add-in. Choose a different name, or close the other workbook or add-in before saving.


    Both Workbooks have a different name. I cannot figure out the issue. Any direction would be appreciated.
    ---------------------------------------------
    Sub SaveFileWhiteBoard()
    
     Application.DisplayAlerts = False
            
            ActiveWorkbook.SaveAs Filename:= _
            "C:\Users\lonneyk\Google Drive\WhiteBoardBinary.xlsm", FileFormat:= _
            xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
            
            
    Application.DisplayAlerts = True
    StartTimerWhiteBoard
    
    End Sub
    Moderators note: Lonney, you almosy had teh code tags correct You need to use [ not <
    Last edited by FDibbins; 08-01-2015 at 08:11 PM.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Save as Script

    Seems like your saving both workbook under the same name "WhiteBoardBinary.xlsm"

    "C:\Users\lonneyk\Google Drive\WhiteBoardBinary.xlsm", FileFormat:= _
    So when you save as the first workbook it is renamed "WhiteBoardBinary.xlsm" and it stay open.
    That's why you get the error when you try to saveas the 2nd workbook.

    Is this really what you want (ie. save under the same name) ? If not, change the saveas name in both macro.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Save as Script

    It would seem that way according to the error nessage, but my second workbook is coded to save that file as a totally different name. This error only happens when both fikes are running.

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Save as Script

    Hi,

    Try replacing "ActiveWorkbook" with "ThisWorkbook" in your code.
    That way, you are sure that the macro is executed in the workbook containing the macro, NOT the activeworkbook at the time the macro is run.

  5. #5
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263
    Ahh - I bet that is the issue! I wont be able to test until tomorrow. I will update after this thread after. Thanks!.

    Quote Originally Posted by GC Excel View Post
    Hi,

    Try replacing "ActiveWorkbook" with "ThisWorkbook" in your code.
    That way, you are sure that the macro is executed in the workbook containing the macro, NOT the activeworkbook at the time the macro is run.

+ 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. VB Script to save document every 2 hours
    By mowens74 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2014, 06:25 AM
  2. VBA: Script to change text color if a change is made
    By hector.febus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2014, 11:06 AM
  3. VBA script to download CSV from Website to Workbook or Save it
    By nalgene5622 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2014, 11:02 AM
  4. [SOLVED] Save As Macro Script
    By Neal in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2006, 11:10 AM
  5. Replies: 1
    Last Post: 07-16-2005, 11:05 AM
  6. VBA Script for copy and paste to save
    By tamato43 in forum Excel General
    Replies: 3
    Last Post: 05-17-2005, 04:06 PM
  7. VB Script file save as with date
    By nixter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2005, 04:06 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