+ Reply to Thread
Results 1 to 10 of 10

Close the source workbook after copying

  1. #1
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82

    Close the source workbook after copying

    Hi,

    I manage to copy a worksheet into a new workbook, but how can I change to the old one and close it without saving ?
    Please Login or Register  to view this content.
    I usually use this code, but I can't go back to the source workbook, how do I do that ?

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    You need to make somesort of refernece to the source book

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82
    How or when do I embed that in the code ? It copies the sheet, copy and pastes just the values (to get rid of all the formulas and calculations) and then saves it to a pre-defined location with a given name. The whole code works like a treat despite being a bit patched together.
    Because if I enter the code just after the copy of the worksheet it comes up with a compiling error. (Sub or function not defined) @
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I have just "assembled" most of the code and adapted it to my purpose, but like I said, works fine for my limited knowledge of VBA. I guess it comes up with the error because the code is still running.
    thanks for the help

  4. #4
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82
    I still haven't found a solution yet, if I try to close the workbook the code is running in it comes up with an error.

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Think mudraker just missed the s

    This worked for me

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  6. #6
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82
    Thanks, that's correct, there was an s missing, but the problem I have is that it doesn't execute the rest of the code properly anymore with this command. I have put the cmd at the end of the posted code, but then it doesn't save it with the defined name at the chosen location anymore. How could I make it finish the whole code and then close the old workbook ?

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This saves then closes

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82
    No, sorry, missunderstanding: Workbook 1 opens a macro, copies a worksheet, tells it with what name and location the new workbook 2 should be saved. Workbook 1 doesn't have to be saved. (see code above)
    But it doesn't execute the rest of the code even when I put the code at the end of the whole macro.

  9. #9
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    I do not fully understand what you mean by Workbook 1 opens a macro

    Is the workbook1 & the source workbook that you refer to the same workbook - If it is try this command before the End Sub command

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-18-2008
    Location
    Switzerland
    MS-Off Ver
    Office 2003
    Posts
    82
    Thanks, that works ! But strange, I have of course added the code before end sub, but it still wouldn't execute the rest of the code (like saving under a specific name)
    What's the difference between this.Workbook and Workbooks("test") if it refers to the same workbook ?
    Last edited by Simon-ch; 01-19-2009 at 03:13 AM.

+ 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