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
Bookmarks