+ Reply to Thread
Results 1 to 5 of 5

VBA to create new Workbook and copy worksheet into it dynamically

  1. #1
    Registered User
    Join Date
    08-20-2013
    Location
    brisbane, australia
    MS-Off Ver
    Excel 2007
    Posts
    14

    VBA to create new Workbook and copy worksheet into it dynamically

    Hi, I am creating a VBA to create a new workbook and copy a worksheet into it. I have the following code I got off youtube, which works for the first time, but when I repeat it gets an error because the code says "book1" and new book is Book2 etc

    Please Login or Register  to view this content.
    I would also like to name the the new workbook from a combination of set term and a variable, the code I have for this is the following:



    Please Login or Register  to view this content.
    I would like to do this all together if possible, create new workbook by the above naming and then copy a worksheet into it.

    cheers Rob
    Last edited by arlu1201; 08-21-2013 at 11:29 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA to create new Workbook and copy worksheet into it dynamically

    use an object when adding the workbook.

    something like

    dim wb as excel.workbook
    set wb =workbooks.add


    then something like

    Sheets("REPORT").Copy BEFORE:=wb.Sheets(1)

    i havent tested this, but should help
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA to create new Workbook and copy worksheet into it dynamically

    Rob

    You can copy a sheet like this to create a new workbook and you can refer to the workbook the code is in using ThisWorkbook.

    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to create new Workbook and copy worksheet into it dynamically

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    08-20-2013
    Location
    brisbane, australia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA to create new Workbook and copy worksheet into it dynamically

    Hi all,

    Thanks for your quick response.

    Norie, Thank you very much, worked well.

    Sorry Admin about code tags, I am male and as such, not very good at reading instructions. lol

+ 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. Dynamically create workbook for employee tracking
    By DevilDog78 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-28-2012, 05:38 AM
  2. Replies: 1
    Last Post: 11-05-2011, 10:45 AM
  3. Dynamically Copy Sub-Totalled group to worksheet if criteria met
    By nezza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2009, 01:51 PM
  4. Create copy of worksheet plus code in the same workbook
    By ahmed-k in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2009, 07:13 PM
  5. On click, copy the corresponding row to a new dynamically created workbook
    By munzer1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2007, 07:40 PM

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