I need help with VBA code to split a workbook and save each individual worksheet as a new workbook. I have XL 2010, but others who will use this file have 2007. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
The code works unitl the last sheet is copied. Then I get a Runtime Error ‘1004’ Method ‘Copy of Object’_Worksheet failed.<o></o>
I’m a macro newbie & would appreciate any advice on where I’ve gone wrong.<o></o>
Code:
[FONT=Arial]Below is the code I have so far:<o:p></o:p>[/FONT]
[FONT=Arial][FONT=Arial] Dim sht As Worksheet<o:p></o:p>[/FONT]
[FONT=Arial] Dim MyCurrPath As String<o:p></o:p>[/FONT]
[FONT=Arial] MyCurrPath = ThisWorkbook.Path<o:p></o:p>[/FONT]
[FONT=Arial] ainput = InputBox("Enter Date for this report")<o:p></o:p>[/FONT]
[FONT=Arial] For Each sht In ActiveWorkbook.Worksheets<o:p></o:p>[/FONT]
[FONT=Arial] sht.Copy<o:p></o:p>[/FONT]
[FONT=Arial] ActiveWorkbook.SaveAs Filename:= _<o:p></o:p>[/FONT]
[FONT=Arial] MyCurrPath & "\" & sht.Name & " OTC Report " & ainput & ".xlsm" _<o:p></o:p>[/FONT]
[FONT=Arial] , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False<o:p></o:p>[/FONT]
[FONT=Arial] ActiveWindow.Close<o:p></o:p>[/FONT]
[FONT=Arial] Next sht<o:p></o:p>[/FONT]
[FONT=Arial]End Sub<o:p></o:p>[/FONT]
[/FONT]
I’m a macro newbie & would appreciate any advice on where I’ve gone wrong.<o></o>