I have workbook which creates an array of worksheet names, then copies those sheets to a new book. It worked fine in excel 2003, but error in excel 2010:
error occurs right after .copy
Copy seems to be created (there's a book1, for example), but excel locks and i'm unable to view it and have to force application closed.
I realize an alternative would be to copy one sheet at a time into a new book, but this seems like a clean (alternative) approach that fails in excel 2010. is there something that's changed (or is there some coding change required to make in work in 2010)?
Thanks,
error occurs right after .copy
Code:
Runtime error:
Method 'Copy' of object 'Sheets' failed
Copy seems to be created (there's a book1, for example), but excel locks and i'm unable to view it and have to force application closed.
I realize an alternative would be to copy one sheet at a time into a new book, but this seems like a clean (alternative) approach that fails in excel 2010. is there something that's changed (or is there some coding change required to make in work in 2010)?
Thanks,
Code:
Sub Break_Out_Regions()
Dim OrigBk As Workbook, Newbk As Workbook
Dim Ws As Worksheet
Dim sReg As String, basepath As String, mgmtpath As String, sTab As String
Dim NewFilename As String, sPath As String, Arr() As String
Dim iYr As Integer, i As Integer, j As Integer, N As Integer
N = 0
Set OrigBk = ThisWorkbook
For Each Ws In OrigBk.Worksheets
If Ws.Visible = xlSheetVisible And Ws.Range("a1").Value = "REPORT" Then 'criteria to select sheets
N = N + 1
ReDim Preserve Arr(1 To N)
Arr(N) = Ws.Name
End If
Next Ws
With OrigBk
.Worksheets(Arr).Copy
End With
Set Newbk = ActiveWorkbook
.....