+ Reply to Thread
Results 1 to 9 of 9

Copy sheet to closed workbook

  1. #1
    Registered User
    Join Date
    11-29-2016
    Location
    Australia
    MS-Off Ver
    10
    Posts
    4

    Copy sheet to closed workbook

    Well I need a little help being a VBA novice.
    I am attempting to save a sheet named Summary from a workbook named RPSDATAFILE.xlsm to a closed workbook named TestDataSheetASX1.xlsx before sheet 1.
    I have used this vba code in Module 4 which appears to work –

    Please Login or Register  to view this content.
    The issue I have is that I am running a code in the open workbook RPSDATAFILE.xlsm that runs an application on time for other modules as below

    Please Login or Register  to view this content.
    When the open workbook code runs it performs the first 4 application on times however when it runs the module to copy the sheet I get the following error message.

    Cannot run the macro ‘sb_Copy_Save_Worksheet_As_Workbook() The macro may not be available in this workbook or all macros may be disabled.
    I think that the macro loses focus to the open workbook code when it runs the copy.
    Any suggestions would be appreciated.
    Last edited by MikeBike; 10-30-2017 at 11:37 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Copy sheet to closed workbook

    Hi Mike and welcome to the forum,

    I'm not sure you can save to a workbook that is closed. See if this site helps with a similar question.

    http://spreadsheetpage.com/index.php...a_closed_file/
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2407 Win 11 Home 64 Bit
    Posts
    24,075

    Re: Copy sheet to closed workbook

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    11-29-2016
    Location
    Australia
    MS-Off Ver
    10
    Posts
    4

    Re: Copy sheet to closed workbook

    Edited post as requested.

  5. #5
    Registered User
    Join Date
    11-29-2016
    Location
    Australia
    MS-Off Ver
    10
    Posts
    4

    Re: Copy sheet to closed workbook

    The vba in the macro module to save to closed workbook does work but not in conjunction with the application on time. This is where the problem lies.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,572

    Re: Copy sheet to closed workbook

    This will copy a named sheet or the 2nd sheet in an open workbook, depends on which line in the code you use, into a closed workbook as the last sheet or as the first sheet.
    Code is in a regular Module in "RPSDATAFILE.xlsm" and is run from this workbook.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-29-2016
    Location
    Australia
    MS-Off Ver
    10
    Posts
    4

    Re: Copy sheet to closed workbook

    Hi Jolivanes,

    The code worked a treat however when the macro is fun it keeps adding a new sheet where shown eg Summary, Summary 1 etc.
    Is there a way to replace the sheet rather than adding a new one each time the macro is run.
    If that solution is too difficult, what about just copying and replacing a range on the sheet.
    I am unsure on how to adjust the code for this.
    Any ideas ?

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,572

    Re: Copy sheet to closed workbook

    If TestDataSheetASX1.xlsx has a sheet called "Summary" in it before copying and pasting, why not check if it has a sheet by that name and if it has, delete it.
    Or you can copy and paste a range if you want.
    Let us know which solution is the best.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,572

    Re: Copy sheet to closed workbook

    This should delete the sheet "Summary" if it exist in wb2 first before copying it from wb1.
    Please Login or Register  to view this content.

+ 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] vba code to copy a specific sheet from a closed workbook to the active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2017, 03:09 AM
  2. [SOLVED] macro to copy specifc sheet in closed workbook to the active sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2017, 09:53 AM
  3. [SOLVED] vba copy specific sheet from closed workbook to active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2017, 01:33 PM
  4. [SOLVED] copy specific sheet from closed workbook to active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2017, 10:26 PM
  5. vba copy specific sheet from closed workbook to active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2017, 02:34 PM
  6. VBA to copy a sheet from a workbook into another workbook that is closed
    By K_Rene in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2016, 10:35 PM
  7. Copy One Sheet From One Closed Workbook To Another Closed WB
    By teshiburu1988 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2009, 11:49 AM

Tags for this Thread

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