+ Reply to Thread
Results 1 to 8 of 8

Need to save a copy of a workbook to another location

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2012
    Location
    San Antonio, Texas
    MS-Off Ver
    Excel 2013
    Posts
    69

    Need to save a copy of a workbook to another location

    I use a workbook that is updated daily. At the end of the shift, I need to save a copy (with macros intact) to another file location. The name of the file will need to be the contents of cell Y2 on the master document. I also need the master to remain open and not close immediately after saving. I've only been able to find tutorials that save without macros and that close the master immediately after saving.

  2. #2
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Need to save a copy of a workbook to another location

    Sub TEST()
    Dim sSavePath As String, sFileName As String
    
    'GET SAVE PATH
    sSavePath = vbNullString: sSavePath = "INSERT FOLDER LOCATION HERE"
    If sSavePath = vbNullString Then GoTo ERROREXIT
    
    'GET FILE NAME
    sFileName = vbNullString: sFileName = CStr(ActiveSheet.Cells(2, 25).value)
    If sFileName = vbNullString Then GoTo ERROREXIT
    
    'SAVE
    ActiveWorkbook.SaveAs Filename:=sFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    ERROREXIT:
    
    End Sub
    Last edited by Mr.PB; 06-27-2018 at 01:16 PM.

  3. #3
    Registered User
    Join Date
    02-19-2012
    Location
    San Antonio, Texas
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: Need to save a copy of a workbook to another location

    Close

    After I'm finished updating the master document, I need the master to retain the changes I made while saving a copy of the document in a shared file location. Once saved, I need the master to remain open. The copy can just be stored without being open. This does save the file labeled as the contents of cell Y2, however it saves to my own personal documents so I'll need to add the address to the shared file location. It also closes the master without saving the changes and leaves the copy open.

    Edit: Maybe nevermind the above. I didnt see the whole thing
    Last edited by aliciaward1001; 06-27-2018 at 01:33 PM.

  4. #4
    Registered User
    Join Date
    02-19-2012
    Location
    San Antonio, Texas
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: Need to save a copy of a workbook to another location

    Sub Save_Copy()
    Dim sSavePath As String, sFileName As String
    
    'GET SAVE PATH
    sSavePath = vbNullString: sSavePath = "\\ant\dept-na\SAT1\Support\Department\2018\End of Shift\EOS_PILOT\"
    If sSavePath = vbNullString Then GoTo ERROREXIT
    
    'GET FILE NAME
    sFileName = vbNullString: sFileName = CStr(ActiveSheet.Cells(2, 25).Value)
    If sFileName = vbNullString Then GoTo ERROREXIT
    
    'SAVE
    ActiveWorkbook.SaveAs Filename:=sFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    ERROREXIT:
    
    End Sub
    This is what I have currently, but it still closes the master without saving and leaves me in the open copied file which it deposits in my documents instead of the designated file.

  5. #5
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Need to save a copy of a workbook to another location

    Try This. You'll need Microsoft Scripting Runtime enabled and be aware that it will overwrite a file of the same name in the save location.
    Sub TEST()
    Dim sMasterFullName As String, sSavePath As String, sSaveFullName As String
    Dim fso As Object
    
    'SAVE ACTIVE WORKBOOK TO ITS CURRENT LOCATION
    ActiveWorkbook.Save
    
    'GET ACTIVE WORKBOOK FULL NAME
    sMasterFullName = vbNullString: sMasterFullName = ActiveWorkbook.FullName
    If sMasterFullName = vbNullString Then GoTo ERROREXIT
    
    'GET SAVE PATH
    sSavePath = vbNullString: sSavePath = "INSERT SAVE PATH HERE"
    If sSavePath = vbNullString Then GoTo ERROREXIT
    
    'GET SAVE FULL NAME
    sSaveFullName = vbNullString: sSaveFullName = sSavePath & CStr(ActiveSheet.Cells(2, 25).value)
    If sSaveFullName = vbNullString Then GoTo ERROREXIT
    
    'COPY FROM ACTIVE WORKBOOK'S CURRENT LOCATION TO SAVE PATH
    Set fso = Nothing: Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    If fso Is Nothing Then GoTo ERROREXIT
    Call fso.CopyFile(sMasterFullName, sSaveFullName)
    
    ERROREXIT:
    Set fso = Nothing
    
    End Sub

  6. #6
    Registered User
    Join Date
    02-19-2012
    Location
    San Antonio, Texas
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: Need to save a copy of a workbook to another location

    Looks like that's gonna work. Only thing now is that the copied version isn't recognized as an excel document.

  7. #7
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Need to save a copy of a workbook to another location

    Be sure the name of the file in cell Y2 has the file type on the right side of the string (probably .xlsm in your case).

  8. #8
    Registered User
    Join Date
    02-19-2012
    Location
    San Antonio, Texas
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: Need to save a copy of a workbook to another location

    Works! thanks

+ 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. [SOLVED] Need code to copy data based on filter criteria to new workbook as save in a file location
    By msantucci in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2015, 02:47 AM
  2. Save As new Workbook at new location that uses part of the Workbook Name
    By stewegg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2015, 04:47 PM
  3. Macro to Auto save a backup copy in a seperate location OR save file with a pop up
    By kdsanderson30 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2014, 12:38 PM
  4. Copy, edit and save workbook to same location as source data file, not macro file.
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 09:01 AM
  5. Replies: 9
    Last Post: 06-24-2013, 04:14 PM
  6. [SOLVED] command button: specified sheet copy and save as new workbook to specified location
    By Zlatko.Pan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-15-2013, 12:28 PM
  7. [SOLVED] delete workbook from one location and save workbook to new locatio
    By Damien in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-03-2006, 10:40 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