+ Reply to Thread
Results 1 to 11 of 11

Change activate workbook to be vba created workbook

  1. #1
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Change activate workbook to be vba created workbook

    Hey folks

    Got stuck in this one and hope someone can help me out.

    I create a workbook by vba and my problem is simply that I cannot change the new workbook to be the activeworkbook where i can select cells and so fourth. I can insert values in cells in the new workbook, but as I need to copy cells from the original workbook to the new one and further manipulate the data, I need to be able to select cells in the new wb. Thanks in advance for your help! Code is following:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Change activate workbook to be vba created workbook

    Try this

    Please Login or Register  to view this content.

    In order to do copy and pasting you'll have to activate the original sheet copy the information then reactivate the new workbook to tell it where to paste it.

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Change activate workbook to be vba created workbook

    Quote Originally Posted by rvasquez View Post
    In order to do copy and pasting you'll have to activate the original sheet copy the information then reactivate the new workbook to tell it where to paste it.
    I do not believe that is 100% accurate. You can simply pass values via .value = .value and avoid activation: (assume "This is a Test!!!!" is entered in Cell A1 of the 1st sheet of the 1st WB):

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  4. #4
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Change activate workbook to be vba created workbook

    Perfect! Just what im looking for. Thanks a lot!

  5. #5
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Change activate workbook to be vba created workbook

    AlvaroSiza: You're right that it's possible to copy and paste across the two wb's, but the problem is that I would quickly run into limitations if I couldnt activate the new wb (e.g. range selection with End(xl..)). But thanks ! (:

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,442

    Re: Change activate workbook to be vba created workbook

    but the problem is that I would quickly run into limitations if I couldnt activate the new wb
    That's not true either. You don't have to select anything to copy it ... just fully qualify the range with the workbook and the range. For example:

    Please Login or Register  to view this content.

    And you would determine the last row to be copied in a similar way:

    Please Login or Register  to view this content.

    Regards
    Last edited by TMS; 05-18-2012 at 04:23 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Change activate workbook to be vba created workbook

    TMShucks: I have no doubt that you are right, but I dont see how you would be able to define the NewWB if it is never the ActiveWorkbook? The copying and last row determination in your post both depends on NewWB to be defined, which was not possible in my initial macro in post #1. Or am I missing something?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,442

    Re: Change activate workbook to be vba created workbook

    For example:

    Please Login or Register  to view this content.

    You don't need all the With ... End With structure but it shows how you can reduce a lot of the code. And it is more efficient.

    Regards

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,442

    Re: Change activate workbook to be vba created workbook

    Better example, same theory:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Change activate workbook to be vba created workbook

    Aha I see. Thanks for the explanation! It certainly made things clearer

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,442

    Re: Change activate workbook to be vba created workbook

    You're welcome.Thanks for the rep.

+ 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