Macro to save sheets into separated workbooks

jalrs

Active Member
Joined
Apr 6, 2022
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Hello guys,

What im looking for here is to save sheets into different workbooks, where workbook name = sheet name. After doing my research i came to this bit of code, but, unfortunately it only copies the first sheet where the name is <> than "Readme" as code shows.

My code:

Sub CriarWBs()

totalsheets = ThisWorkbook.Sheets.Count

For i = 1 To totalsheets

strsheetname = ThisWorkbook.Sheets(i).Name

If strsheetname <> "Readme" Then

Sheets(strsheetname).Select
Sheets(strsheetname).Copy
ActiveWorkbook.SaveAs Filename:="C:\Users\joafrodrigue\Desktop\teste\Difusao\" & strsheetname & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close

End If

Next

End Sub

Thank you very much guys!
 

Attachments

  • 1.png
    1.png
    6.2 KB · Views: 8
  • 2.png
    2.png
    10.7 KB · Views: 9
  • 3.png
    3.png
    5 KB · Views: 9
Good luck with it. Please keep in mind that to get a working solution, you need to have consistency in how the data should be organized. Too many variables, especially if they change from time to time, make it very hard to code.
Really appreciate your feedback, thank you!
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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