Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Created April 23, 2020 03:39
Show Gist options
  • Save DataSolveProblems/c5f59b4ca727ee3cbe41f09472a8583a to your computer and use it in GitHub Desktop.
Save DataSolveProblems/c5f59b4ca727ee3cbe41f09472a8583a to your computer and use it in GitHub Desktop.
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