Macro to copy sheets and create individual files

rammergu

New Member
Joined
Oct 17, 2006
Messages
8
Hi,

I maintain a workbook with 11 worksheets in it (named Sheet1, sheet2, etc).Each sheet contains information that i have to email to individuals. Ex: sheet 1 to user A, sheet 2 to user B, etc.

Currently, i copy the sheet and paste it to a new workbook, save it, and then email to all the 11 users.

Can you help me with the macro, which automates this process. It should basically copy the sheet, create a new book, and the file name should be the same as the sheet name.

Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
Hi -
Welcome to the board.
try;
Code:
Sub TEST()
Dim NB, MB As Workbook
Set MB = ThisWorkbook
Dim I As Long
For I = 1 To Sheets.Count
    Set NB = Workbooks.Add
        ThisWorkbook.Sheets(I).Cells.Copy NB.Sheets(1).Range("A1")
        NB.SaveAs "C:\" & NB.Sheets(I).Name & ".XLS"
        NB.Close
Next
End Sub
 

rammergu

New Member
Joined
Oct 17, 2006
Messages
8
Thanks for the code. The code is working, however it not how exactly how i wanted it. I think i didnt explain very well,

there are 11 sheets, i go to each sheet tab, right click on it, click on 'move or copy', drop down and select '(new book)', check on 'copy'

A new work book is created with only one worksheet, retaining the name of the sheet and all the formatting.

Once this is done, i do a save as, and then close.
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
how about this one?
Code:
Sub TEST()
Dim NB, MB As Workbook
Set MB = ThisWorkbook
Dim I, II As Long
For I = 1 To MB.Sheets.Count
    Set NB = Workbooks.Add
        MB.Sheets(I).Cells.Copy NB.Sheets(1).Range("A1")
        NB.Sheets(1).Name = MB.Sheets(I).Name
        For II = 2 To NB.Sheets.Count
            Application.DisplayAlerts = False
            NB.Sheets(2).Delete
            Application.DisplayAlerts = True
        Next
        NB.SaveAs "C:\" & MB.Sheets(I).Name & ".XLS"
        NB.Close
Next
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,302
Office Version
  1. 365
Platform
  1. Windows
Try this.
Code:
For Each ws In Worksheets
      ws.Copy
      Set wb = ActiveWorkbook
      wb.SaveAs ThisWorkbook.Path & "/" & ws.Name
      ' put code to email here
      wb.Close
Next ws
 

Forum statistics

Threads
1,140,912
Messages
5,703,128
Members
421,276
Latest member
davidfrommke

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
Top