Hello Everyone,
I have a problem with copying specific worksheets to new workbooks, below is my code, but I don't know how to skip hidden sheets, something like If Worksheets.Visible = True Then do the code, would be great but I wonder if something like a list would be best choice. For example "-General" is the main sheet and sheets belongs to this are: "1" "2" "3"
Macro will copy only sheets which are in the A1:A4 range, so the hidden sheets will be skipped too! Thank you all for help!
I have a problem with copying specific worksheets to new workbooks, below is my code, but I don't know how to skip hidden sheets, something like If Worksheets.Visible = True Then do the code, would be great but I wonder if something like a list would be best choice. For example "-General" is the main sheet and sheets belongs to this are: "1" "2" "3"
Macro will copy only sheets which are in the A1:A4 range, so the hidden sheets will be skipped too! Thank you all for help!
Code:
[COLOR=#333333]Sub Report() [/COLOR] Dim Wb As Workbook
Dim dateStr As String
Dim NewWorkBookName As String
Dim Links As Variant
Dim i As Integer
Dim v As Variant, ws As Worksheet
Dim tmpV As Variant
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
ReDim v(1 To Sheets.Count)
For Each ws In ThisWorkbook.Worksheets
If LCase(Left(ws.Name, 1)) = "-" Then
x = x + 1
v(x) = ws.Name
Else
v(x) = v(x) & "," & ws.Name
End If
Next ws
Set Wb = ActiveWorkbook
dateStr = Format(Date, "MM-DD-YYYY")
For a = 1 To x
tmpV = Split(v(a), ",")
NewWorkBookName = tmpV(0)
Wb.Sheets(tmpV).Copy
With ActiveWorkbook
Links = .LinkSources(xlExcelLinks)
If Not IsEmpty(Links) Then
For i = 1 To UBound(Links)
.BreakLink Links(i), xlLinkTypeExcelLinks
Next i
End If
End With
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & NewWorkBookName & " " & dateStr
ActiveWorkbook.Close
Next a
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
End Sub