+ Reply to Thread
Results 1 to 4 of 4

VBA code to always select next available new workbook

  1. #1
    Registered User
    Join Date
    12-22-2005
    Location
    Sarasota, FL
    Posts
    26

    Question VBA code to always select next available new workbook

    Hi

    I have a macro that adds a new workbook and copies two sheets to it. However the macro crashes if the new workboox is not book1 and it is kind of a bummer.
    I have not been able to figure how to code something to just look at the newest workbook and copying the stuff...without vba looking at book1 as the new workbook...just whatever is available.

    Here's what I currently have...help appreciated.

    Workbooks.Add
    Windows("TC Report.xls").Activate
    Sheets(Array("ST Report", "EF Report")).Select
    Sheets("EF Report").Activate
    Sheets(Array("ST Report", "EF Report")).Copy Before:=Workbooks("Book1").Sheets _
    (1)
    Windows("TC Report.xls").Activate
    Sheets("ST Report").Select

  2. #2
    Dick Kusleika
    Guest

    Re: VBA code to always select next available new workbook

    wayliff wrote:
    >
    > Workbooks.Add
    > Windows("TC Report.xls").Activate
    > Sheets(Array("ST Report", "EF Report")).Select
    > Sheets("EF Report").Activate
    > Sheets(Array("ST Report", "EF Report")).Copy
    > Before:=Workbooks("Book1").Sheets _
    > (1)
    > Windows("TC Report.xls").Activate
    > Sheets("ST Report").Select


    Dim wb As Workbook

    Set wb = Workbooks.Add

    Workbooks("TC Report.xls").Sheets(Array("ST Report", "EF Report")).Copy _
    Before:=wb.Sheets(1)


    --
    **** Kusleika
    MVP-Excel
    www.dailydoseofexcel.com



  3. #3
    Registered User
    Join Date
    12-22-2005
    Location
    Sarasota, FL
    Posts
    26
    Thank you so much for your help...

    This is where I can see that I have way to go in code efficiency and knowledge...

  4. #4
    Dick Kusleika
    Guest

    Re: VBA code to always select next available new workbook

    wayliff wrote:
    > Thank you so much for your help...
    >


    You're welcome.

    > This is where I can see that I have way to go in code efficiency and
    > knowledge...


    Well, you're on your way. Here's some more info on selecting and
    activating:

    http://www.*****-blog.com/archives/2...-and-activate/

    --
    **** Kusleika
    MVP-Excel
    www.dailydoseofexcel.com



+ 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