+ Reply to Thread
Results 1 to 5 of 5

Thread: Run time error "9" when copy all sheets to a new workbook

  1. #1
    Registered User
    Join Date
    01-06-2009
    Location
    KL, Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    36

    Run time error "9" when copy all sheets to a new workbook

    Hi,

    I want to copy over the open workbook to a new template file but i got the run time "9" error.

    Sub CopySheets()
    
        
        Dim WB As Workbook
        Dim WB2 As Workbook
    
        Set WB = ThisWorkbook
    
        Workbooks.Add Template:="C:\xxx.xltm"
        Set WB2 = Workbooks("xxx.xlsm")
    
        WB.Sheets.Copy Before:=WB2.Sheets(1)
    
    
    End Sub
    I hope someone can assist me to fix the error.

    Thank you in advance.
    Last edited by Apple Ling; 07-07-2011 at 02:10 AM.

  2. #2
    Registered User
    Join Date
    01-06-2009
    Location
    KL, Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: Run time error "9" when copy all sheets to a new workbook

    Anyone help please.

  3. #3
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Run time error "9" when copy all sheets to a new workbook

    for Excel 2003 template workbook:
    Sub test()
    Application.ScreenUpdating = 0
    With ActiveWorkbook: .Sheets.Copy: .SaveAs "C:\Temp.xlt": End With
    Application.ScreenUpdating = 1
    End Sub

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Run time error "9" when copy all sheets to a new workbook

    maybe

    Sub CopySheets()
    
        
        Dim WB As Workbook
        Dim WB2 As Workbook
    
        Set WB = ThisWorkbook
    
        Workbooks.Add Template:="C:\xxx.xltm"
        Set WB2 = ActiveWorkbook
        WB.Sheets.Copy Before:=WB2.Sheets(1)
    
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Registered User
    Join Date
    01-06-2009
    Location
    KL, Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: Run time error "9" when copy all sheets to a new workbook

    Thank you very much. It's works fine now

+ 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.2.0