Dear All,
I have code that works but it is very slow about 5mins.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
<o
> </o
>
It is creating 170 new files from current template and it runs vba in new files where it paste special values and removes all vba from New file and save it closes file.<o
></o
>
Is there a faster way to do this?
Biz
I have code that works but it is very slow about 5mins.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
<o
It is creating 170 new files from current template and it runs vba in new files where it paste special values and removes all vba from New file and save it closes file.<o
Code:
Sub Createfiles()
Dim r As Range, myDir As String
Dim ActBook As Workbook, NewBook As Workbook
Dim aStartTime
aStartTime = Now()
'Speeding Up VBA Code
Application.ScreenUpdating = False 'Prevent screen flickering
Application.Calculation = False 'Preventing calculation
Application.DisplayAlerts = False 'Turn OFF alerts
Application.EnableEvents = False 'Prevent All Events
Application.DisplayStatusBar = False
Set ActBook = ActiveWorkbook
myDir = "c:\Temp\"
With Sheets("BUs")
For Each r In .Range("a1", .Range("a" & Rows.Count).End(xlUp))
If Not IsEmpty(r) Then
With Sheets("2006-07")
.Range("b1") = r.Value
End With
ThisWorkbook.SaveCopyAs (myDir & "BU " & r.Value & ".xls")
'Open New File created
Workbooks.Open Filename:=myDir & "BU " & r.Value & ".xls", UpdateLinks:=3
Set NewBook = ActiveWorkbook
Application.Run "'BU " & r.Value & ".xls'" & Chr(33) & "SPaste"
Application.Run "'BU " & r.Value & ".xls'" & Chr(33) & "DeleteAllVBA"
'Save New workbook after doing Paste Special values and Removing VBA
With NewBook
.Save
.Close
End With
ActBook.Activate
End If
Next
End With
'Release memory
Set ActBook = Nothing
Set NewBook = Nothing
'Speeding Up VBA Code
Application.ScreenUpdating = True 'Prevent screen flickering
Application.Calculation = True 'Preventing calculation
Application.DisplayAlerts = True 'Turn OFF alerts
Application.EnableEvents = True 'Prevent All Events
Application.DisplayStatusBar = True
MsgBox "Time taken: " & Format(Now() - aStartTime, "h:mm:ss"), vbInformation, "Time taken"
End Sub
Sub SPaste()
With Sheets("2006-07").Range("D5:P156")
.Value = .Value
End With
End Sub
Sub DeleteAllVBA()
'Dim VBComp As VBIDE.VBComponent
'Dim VBComps As VBIDE.VBComponents
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp
End Sub
Is there a faster way to do this?
Biz