I have the following sub to create a new workbook, close it, copy a worksheet in the active workbook, open the new workbook, and then paste it in. It worked in Excel 2007, but I've switched to 2010 and now I get an Application Defined or Object defined error (1004). It stops at the third line (ActiveWorkbook.SaveAs......) with the error. It does create a new workbook, but it's a Bookn file name (as in Book1 etc.), but never saves it. UserName is the output of an InputBox (Dim UserName As String, ). This works great and puts the string in a cell. I've tried using the Worksheet Range where UserName is stored in the file name and still get the same error.
Sub CreateCopy()
Workbooks.Add
ChDir "C:\Users\Jim 2\Desktop\Sample Results"
ActiveWorkbook.SaveAs Filename:="C:\Users\Jim 2\Desktop\Sample_Results\"UserName & Format(Now(), "mm-dd-yyyy hh:mm").xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Sheets("Sheet1").Select
Cells.Select
Selection.Copy
Workbooks.Open Filename:="C:\Users\Jim 2\Desktop\Sample_Results\UserName.xlsx"
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Sub CreateCopy()
Workbooks.Add
ChDir "C:\Users\Jim 2\Desktop\Sample Results"
ActiveWorkbook.SaveAs Filename:="C:\Users\Jim 2\Desktop\Sample_Results\"UserName & Format(Now(), "mm-dd-yyyy hh:mm").xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Sheets("Sheet1").Select
Cells.Select
Selection.Copy
Workbooks.Open Filename:="C:\Users\Jim 2\Desktop\Sample_Results\UserName.xlsx"
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Last edited: