embellishedego
03-11-2017, 12:47 AM
So here's my brain-killer:
I need to save a Glossary tab with each of my worksheets (Plant Code Tabs) in this workbook to send out files to managers. I have the code that creates the individual Plant Code files and saves them to my desktop, using the plant codes for the new workbook name. Can anyone give me a hand here with adding a segment to my loop to add the glossary tab to my new workbooks?
Also, can I use an "else" to only create specific files if I don't want files of every single tab? I'm new to VBA, and haven't really figured out how to declare and specify details with loops yet. Thank you!
Sub SaveShtsAsBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Sheets(Array("ActiveSheet", "Glossary of Terms")).Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs Filename:=MyFilePath _
& "\" & SheetName & ".xlsx"
.Close savechanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
I need to save a Glossary tab with each of my worksheets (Plant Code Tabs) in this workbook to send out files to managers. I have the code that creates the individual Plant Code files and saves them to my desktop, using the plant codes for the new workbook name. Can anyone give me a hand here with adding a segment to my loop to add the glossary tab to my new workbooks?
Also, can I use an "else" to only create specific files if I don't want files of every single tab? I'm new to VBA, and haven't really figured out how to declare and specify details with loops yet. Thank you!
Sub SaveShtsAsBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Sheets(Array("ActiveSheet", "Glossary of Terms")).Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs Filename:=MyFilePath _
& "\" & SheetName & ".xlsx"
.Close savechanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)