Created
April 23, 2020 03:39
-
-
Save DataSolveProblems/c5f59b4ca727ee3cbe41f09472a8583a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Sub ExportWorksheets() | |
Dim wbSource As Workbook, wbTarget As Workbook | |
Dim worksheetList As String 'Use colon as seperator since you cannot have colon in your worksheet name | |
Dim worksheetArr As Variant | |
Dim arrIndx As Long | |
On Error GoTo errHandle | |
worksheetList = "GOOGL:TSLA:AAPL" | |
worksheetArr = Split(worksheetList, ":") | |
If UBound(worksheetArr) = -1 Then Exit Sub | |
Set wbSource = ThisWorkbook | |
Set wbTarget = Workbooks.Add | |
For arrIndx = LBound(worksheetArr) To UBound(worksheetArr) | |
ThisWorkbook.Worksheets(worksheetArr(arrIndx)).Copy wbTarget.Worksheets(wbTarget.Worksheets.Count) | |
Next arrIndx | |
MsgBox "Export complete.", vbInformation | |
CleanObjects: | |
Set wbTarget = Nothing | |
Set wbSource = Nothing | |
Exit Sub | |
errHandle: | |
MsgBox "Error: " & Err.Description, vbExclamation | |
GoTo CleanObjects | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment