+ Reply to Thread
Results 1 to 5 of 5

Open 2nd workbook,, copy information accross and then close both workbooks

  1. #1
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Open 2nd workbook,, copy information accross and then close both workbooks

    Good Morning All


    I have 2 workbooks.... Central GDP Training and Databackup

    The Central file if the main one for all the information.... Before the file closes it should be opening the backup file,, copying the information over then closing the backup before closing itself

    I am using this to copy information from several worksheets in to the backup file... when the SaveBackup is assigned to a button its working well and doing as it should.

    However when I want it to run automatically before the Central file closes I am receiving an error message for Subscript Out of Range

    Could someone please point ou where I am going wrong

    Many thanks

    Jim

    Please Login or Register  to view this content.
    Last edited by JamesT1; 10-17-2023 at 02:55 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Open 2nd workbook,, copy information accross and then close both workbooks

    If you want to automatically copy the ranges to the backup file when you close the Training file, place this macro in the code module for ThisWorkbook in the Training file. Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the left hand pane, double click on "ThisWorkbook". Copy/paste the macro into the empty window that opens up. Close the window to return to your sheet. When you close the Training file, the ranges to the backup file will be copied over and both files will close.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    Another ThisWorkbook module VBA event procedure :

    PHP Code: 
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        If 
    Not Saved Then Save
        SaveCopyAs 
    "H:\Administration\GDP SOP Training\Data Backup\Databackup.xlsm"
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Or this ...


    A ThisWorkbook module VBA event variation :

    PHP Code: 
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
            If 
    Not Saved Then Save
       With Application
           
    .DisplayAlerts False
           
    .ScreenUpdating False
            Sheets
    ("Data").Copy
            Sheets
    ("Lists").Copy ActiveWorkbook.Sheets(1)
            
    Sheets("Archive").Copy ActiveWorkbook.Sheets(2)
            
    Sheets("ListsArchive").Copy ActiveWorkbook.Sheets(3)
            
    ActiveWorkbook.SaveAs "H:\Administration\GDP SOP Training\Data Backup\Databackup"51
            ActiveWorkbook
    .Close
           
    .DisplayAlerts False
           
    .ScreenUpdating True
       End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Re: Open 2nd workbook,, copy information accross and then close both workbooks

    Marc L

    Many thanks,,, this works

    Jim

+ 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. save & close all open workbooks except workbook which macro is ran from
    By webcam723 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2023, 04:34 AM
  2. Copy from first workbook, close open new workbook paste close
    By johncarr1952 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-04-2021, 08:50 AM
  3. [SOLVED] Issue with Open, copy, close Macro - when trying to close workbook Clipboard error
    By seanpcorbett1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2016, 05:14 PM
  4. [SOLVED] workbook won't close when other workbooks are open
    By Jerbinator in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-11-2016, 08:21 AM
  5. [SOLVED] How can I completely close a specific workbook without closing other open workbooks
    By Sc0ut in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2016, 04:06 PM
  6. [SOLVED] Open Multiple Workbooks, Record names, Copy paste to Active Workbook, Close the Workbooks
    By vba_madness in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2013, 06:09 AM
  7. Look for and Open saved workbook retrieve information into new WB then close them
    By Aeneren in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-27-2012, 10:42 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