View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_3_] Robert Crandal[_3_] is offline
external usenet poster
 
Posts: 161
Default Can this code be optimized?

I have the following code:

'--------------------------------------------------------
Sub TheCode()
Dim j As Integer
Dim newfile As String
Application.ScreenUpdating = False

For j = 1 To 5
Workbooks.Open Filename:="C:\main.xlsm"
newfile = "version" & CStr(j) & ".xlsm"
ActiveWorkbook.SaveAs Filename:="C:\" & newfile, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
CreateBackup:=False
Workbooks(newfile).Sheets(1).Range("A1") = "1"
Workbooks(newfile).Save
Workbooks(newfile).Close
Next j

Application.ScreenUpdating = True
End Sub
'--------------------------------------------------------

This code requires that a blank Excel file named "main.xlsm"
exists on the C: drive. The code then creates 5 new files on
the C: drive.

Does anyone know if this code can be improved or
optimized to run faster? Would anybody code this
differently?

I'm asking for a faster solution because this code seems
to run much much slower on Excel 2013, as compared to
Excel 2010. Are there any commands here that are
inefficient for Excel 2013?

Thanx!