Try this test macro
Create a workbook with all the userforms and code you want
Change the path/file name in this line
Set Destwb = Workbooks.Open("C:\Users\Ron\Documents\template.xls")
Be sure that this file is not open when you run the macro
Be sure that this workbook have the same file format as the workbook with the code
If it is working OK you can add the mail code in the same macro
Sub Copy_Every_Sheet_To_New_Workbook_Test()
'Working in 97-2007
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'Copy every sheet from the workbook with this macro
Set Sourcewb = ThisWorkbook
'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "\" & Sourcewb.Name & " " & DateString
MkDir FolderName
'Copy every visible sheet to a new workbook
For Each sh In Sourcewb.Worksheets
'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 Then
Set Destwb = Workbooks.Open("C:\Users\Ron\Documents\Book5.xlsm")
sh.Copy after:=Destwb.Worksheets(Destwb.Worksheets.Count)
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
If Sourcewb.Name = .Name Then
MsgBox "Your answer is NO in the security dialog"
GoTo GoToNextSheet
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
'Save the new workbook and close it
With Destwb
.SaveAs FolderName _
& "\" & sh.Name & FileExtStr, _
FileFormat:=FileFormatNum
.Close False
End With
End If
GoToNextSheet:
Next sh
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm
ryguy7272 said:
I mail it to about 9-10 people, all listed in a Range in Excel, using your
code:
http://www.rondebruin.nl/mail/folder3/message.htm
They fill out some information on a single SS, using a few UserForms, and
mail it back to me:
http://www.rondebruin.nl/mail/folder2/mail2.htm
All the data is stored in Access. I created a work-around, using Excel,
because many people in my office do not have MS Access, or do not know how to
use Access.
I am thinking the 'Template' option may be the way to go with this. Hoever,
I think I will have to scrap the whole 'Create a workbook from every
worksheet in your workbook' idea (which, by the way, I love):
http://www.rondebruin.nl/copy6.htm
Any other ideas?
Thanks so much,
Ryan---