Results 1 to 2 of 2

Split into different workbooks

Threaded View

  1. #1
    Registered User
    Join Date
    12-17-2008
    Location
    edinburgh, uk
    Posts
    46

    Unhappy Split into different workbooks

    Hi guys,
    I'm stumped by this. I have a workbook "Activities.xls" with various tabs in it. What i want to do is check to see if a specific tab exists and if it does i want to copy it to a new workbook called "test.xls". In my code below - wsname is the tab i want to check exists and if it does i want to past it into the test.xls workbook. Then i want to save & close the new workbook. Please help!

    Doesn't work at all :-(

    Sub SplitWorksheets()
    
    Dim ws As Worksheet
    Dim sheetExist As Boolean
    Dim wsname As String
    Dim wb As Workbook
    
    workbooks.add
        ActiveWorkbook.SaveAs Filename:= _
        "C:\test.xls", FileFormat:=xlNormal, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False
        Windows("test.xls").Activate
        Sheets("Sheet2").Select
        Application.CutCopyMode = False
        ActiveWindow.SelectedSheets.Delete
        Sheets("Sheet3").Select
        ActiveWindow.SelectedSheets.Delete
        Sheets("Sheet1").Select
    
     wsname = "User Test"
        Windows("Activities.xls").Activate
        For Each ws In Worksheets
        If UCase(wsname) = UCase(ws.Name) Then
        sheetExist = True
        Exit For
        End If
        Next
        If sExist = True Then
        Windows("Activities.xls").Activate
        Sheets(wsname).Select
        Cells.Select
        Selection.Copy
        Windows("test.xls").Activate
        Sheets.Add.Name = wsname
        Sheets(wsname).Select
        Cells.Select
        ActiveSheet.Paste
        Windows("Activities.xls").Activate
        Sheets(wsname).Select
        Application.CutCopyMode = False
        Windows("test.xls").Activate
        Windows("Activities.xls").Activate
        Sheets(wsname).Select
        ActiveWindow.SelectedSheets.Delete
        Else
        End If
    '     Windows("test.xls").Activate
            ActiveWorkbook.Save
            ActiveWindow.Close
    end sub
    Last edited by davesexcel; 12-24-2008 at 05:04 AM. Reason: No Code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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