stelmarkov
New Member
- Joined
- Jun 6, 2011
- Messages
- 5
RE: MACRO to save worksheets as seperate files ?
Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
I've found in your archive the Macro code Posted by Dank on November 14, 2001 12:51 AM re how to Saves worksheets as separate files from one main workbook<o></o>
<o></o>
This code does save the worksheets as a separate files and that is exactly what I’ve been looking for however <o></o>
<o></o>
1) I don't need to save each worksheet from my master work book e.g I need to save only 20 separate files
<o> </o>
How do I amend the below code posted by Dank ? Can we specify in the code the range of the worksheets I need to save ? <o></o>
<o> </o>
Please note that I am a beginner and I found the below code a bit simple and understanding so is it possible to amend the below code to my need
PS. The Worksheets that I need to copy and distribute are named with different Doctors Surnames<o></o>
<o> </o>
2) I work in Excel 2007 but most of my master workbooks are saved in .xls and not in .xlsx as we send the files to external users and not every user have latest version of excel, Dank’s macro currently saves all files in .xlsx<o></o>
<o> </o>
I’ve tried to amend the following Save As macro to <o></o>
wbDest.SaveAs strSavePath & sht.Name & " " & Format(DateSerial(Year(Now), Month(Now) - 1, 1), "mmmm yy") & ".xls")
<o> </o>
The Marco saves the file with ext .xls BUT when I open the file, message says that” The file is saved in different format than specified in the file extension” Where in the macro can you specify the extension of the file then?<o></o>
<o> </o>
<o></o>I also tried to amend / add the following But I am getting the message “Object Variable or with block variable not set”<o></o>
<o> </o>
Dim strFile As String<o></o>
strFile = Dir(strSavePath & sht.Name & " " & Format(DateSerial(Year(Now), Month(Now) - 1, 1), "mmmm yy") & ".xls")<o></o>
wbDest.SaveAs strFile<o></o>
<o> </o>
<o>Thanking you in advance</o>
<o>Kind Regards,</o>
<o>Stal</o>
<o> </o>
Please refer to the Macro posted by Dank <o></o>
Sub CreateWorkbooks()
'Creates an individual workbook for each worksheet in the active workbook.
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim sht As Object 'Could be chart, worksheet, Excel 4.0 macro,etc.
Dim strSavePath As String <o></o>
<o> </o>
On Error GoTo ErrorHandler<o></o>
<o></o>
Application.ScreenUpdating = False 'Don't show any screen movement <o></o>
strSavePath = "C:\Temp\" 'Change this to suit your needs <o></o>
<o> </o>
Set wbSource = ActiveWorkbook <o></o>
For Each sht In wbSource.Sheets
sht.Copy
Set wbDest = ActiveWorkbook
wbDest.SaveAs strSavePath & sht.Name
wbDest.Close 'Remove this if you don't want each book closed after saving.
Next <o></o>
Application.ScreenUpdating = True <o></o>
Exit Sub <o></o>
ErrorHandler: 'Just in case something hideous happens
MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."
End Sub
Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
I've found in your archive the Macro code Posted by Dank on November 14, 2001 12:51 AM re how to Saves worksheets as separate files from one main workbook<o></o>
<o></o>
This code does save the worksheets as a separate files and that is exactly what I’ve been looking for however <o></o>
<o></o>
1) I don't need to save each worksheet from my master work book e.g I need to save only 20 separate files
<o> </o>
How do I amend the below code posted by Dank ? Can we specify in the code the range of the worksheets I need to save ? <o></o>
<o> </o>
Please note that I am a beginner and I found the below code a bit simple and understanding so is it possible to amend the below code to my need
PS. The Worksheets that I need to copy and distribute are named with different Doctors Surnames<o></o>
<o> </o>
2) I work in Excel 2007 but most of my master workbooks are saved in .xls and not in .xlsx as we send the files to external users and not every user have latest version of excel, Dank’s macro currently saves all files in .xlsx<o></o>
<o> </o>
I’ve tried to amend the following Save As macro to <o></o>
wbDest.SaveAs strSavePath & sht.Name & " " & Format(DateSerial(Year(Now), Month(Now) - 1, 1), "mmmm yy") & ".xls")
<o> </o>
The Marco saves the file with ext .xls BUT when I open the file, message says that” The file is saved in different format than specified in the file extension” Where in the macro can you specify the extension of the file then?<o></o>
<o> </o>
<o></o>I also tried to amend / add the following But I am getting the message “Object Variable or with block variable not set”<o></o>
<o> </o>
Dim strFile As String<o></o>
strFile = Dir(strSavePath & sht.Name & " " & Format(DateSerial(Year(Now), Month(Now) - 1, 1), "mmmm yy") & ".xls")<o></o>
wbDest.SaveAs strFile<o></o>
<o> </o>
<o>Thanking you in advance</o>
<o>Kind Regards,</o>
<o>Stal</o>
<o> </o>
Please refer to the Macro posted by Dank <o></o>
Sub CreateWorkbooks()
'Creates an individual workbook for each worksheet in the active workbook.
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim sht As Object 'Could be chart, worksheet, Excel 4.0 macro,etc.
Dim strSavePath As String <o></o>
<o> </o>
On Error GoTo ErrorHandler<o></o>
<o></o>
Application.ScreenUpdating = False 'Don't show any screen movement <o></o>
strSavePath = "C:\Temp\" 'Change this to suit your needs <o></o>
<o> </o>
Set wbSource = ActiveWorkbook <o></o>
For Each sht In wbSource.Sheets
sht.Copy
Set wbDest = ActiveWorkbook
wbDest.SaveAs strSavePath & sht.Name
wbDest.Close 'Remove this if you don't want each book closed after saving.
Next <o></o>
Application.ScreenUpdating = True <o></o>
Exit Sub <o></o>
ErrorHandler: 'Just in case something hideous happens
MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."
End Sub