+ Reply to Thread
Results 1 to 13 of 13

Close open workboos with script

Hybrid View

  1. #1
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Close open workboos with script

    Try

     
    
        Dim stwb1 As String, wb2 As Workbook, stPathPlus As String
        stwb1 = ThisWorkbook.Name
        stPathPlus = Sheets("Sheet1").Range("C5") ' where "Sheet1" is the sheet TAB name and C5 contains a character string
        ActiveWorkbook.Save    
        ActiveWorkbook.SaveAs Filename:=stPathPlus
        Set wb2 = ThisWorkbook
        Workbooks.Open Filename:=stwb1
        wb2.Close
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  2. #2
    Registered User
    Join Date
    12-30-2012
    Location
    Nacogdoches, Tx
    MS-Off Ver
    Excel 2015
    Posts
    65

    Re: Close open workboos with script

    I copied & Pasted the code, it worked through saving the backup as I named it on sheet1 range c5.

    However it then gives me a run-time error 1004

    saying:
    The file could not be accessed. Try one of the following:
    Make sure the specified folder exists.
    Make sure the folder that contains the file is not read only
    Make sure the file name does not contain any of the following charcters: <>?[]:|ir*
    Make sure the file/path name doesn't contain more than 218

    I press the Debug key and it highlights the code line:

    ActiveWorkbook.SaveAs Filename:=stPathPlus
    It did save the file as I named it for a backup, the stops there.

  3. #3
    Registered User
    Join Date
    12-30-2012
    Location
    Nacogdoches, Tx
    MS-Off Ver
    Excel 2015
    Posts
    65

    Re: Close open workboos with script

    I copied & Pasted the code, it worked through saving the backup as I named it on sheet1 range c5.

    However it then gives me a run-time error 1004

    saying:
    The file could not be accessed. Try one of the following:
    Make sure the specified folder exists.
    Make sure the folder that contains the file is not read only
    Make sure the file name does not contain any of the following charcters: <>?[]:|ir*
    Make sure the file/path name doesn't contain more than 218

    I press the Debug key and it highlights the code line:

    [Select Code]

    ActiveWorkbook.SaveAs Filename:=stPathPlus

    It did save the file as I named it for a backup, the stops there.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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