Storing Multiple Sheet References in a Cell to Use in a Macro

Flinger

New Member
Joined
Feb 24, 2011
Messages
3
I have a large workbook that I need to split into smaller parts, saved and emailed to people. I am creating a control sheet to simplify coding and support. The control sheet will have three columns.

Column 1 = the sheets to be sent
Column 2 = file name
Column 3 = email address

I have written a macro to loop through the control sheet. First it selects the sheets in Column 1, then it copies the selected sheets saves the new workbook with the name in Column 2, and emails the workbook to Column 3.

The problem I am having is how do I store the sheets to be sent in a single cell and how do I use it in my macro. This is a simplified version of what I have that doesn't contemplate the email portion yet.

Code:
Sub Email()
Dim strTabs As String
Dim strName As String
Dim strEmail As String

  
For Row = 1 To 5
    
 
strTabs = ActiveSheet.Cells(Row, 1)
strName = ActiveSheet.Cells(Row, 2)
strEmail = ActiveSheet.Cells(Row, 3)
    
    
Sheets(strTabs).Select
Sheets(strTabs).Copy
ActiveWorkbook.SaveAs Filename:= _
        "C:\Test\" & strName, _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

  
Next Row

End Sub

My question boils down to how do I store the tabs names in Column 1 and how do I need to reference them in the code?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Give this a go. It assumes you enter in the sheets you need seperated by a comma without a space.

i.e. in A1 you have - Main,Summary,Test1

Code:
Sub Email()
Dim strTabs As String
Dim strName As String
Dim strEmail As String
Dim Row As Long

Dim ws As Worksheet
Dim wb As Workbook
  
Set ws = ActiveSheet
  
For Row = 1 To 5
    
 
    strTabs = ws.Cells(Row, 1)
    strName = ws.Cells(Row, 2)
    strEmail = ws.Cells(Row, 3)
    
    'Create new workbook to save sheets into
    Set wb = Workbooks.Add
    
    'Copy sheets into new workbook
    ThisWorkbook.Sheets(Split(strTabs, ",")).Copy wb.Sheets(1)
    
    wb.SaveCopyAs Filename:= _
        "C:\Test\" & strName ', _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        
    wb.Close False

  
Next Row

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top