Hello, for experimental purpose I use code below to create 3000 - 300000 files. This process is to slow and it's seems, that PC hangs.Please, help me to improve this code to work faster.
Sub BhBp_SaveAsCopy()For X = 1 To 3000ActiveDocument.SaveAsCopy ActiveDocument.FilePath & "DOCUMENT_" & String(10 - Len(X), "0") & X & ".cdr"NextEnd Sub
I see you like to load the computer with unnecessary work. Try the code below.Sub FileCloning() Dim DirFrom$, FileFrom$, DirTo$, FileTo$, X& DirFrom = ActiveDocument.FilePath FileFrom = ActiveDocument.Name DirTo = DirFrom For X = 1 To 3000 FileTo = Right("0000000000" & X, 10) & ".cdr" FileCopy DirFrom & FileFrom, DirTo & FileTo Next XEnd Sub
For the purity of the experiment use =format С:= please!(this is a joke. Don't do that.)
To SaveAs 3000 files
There are significant differences in work time of different code. Difference of time work is about 50 sec
ActiveDocument.SaveAsCopy ActiveDocument.FilePath & "DOCUMENT_" & String(10 - Len(X), "0") & X & ".cdr" '242 sec
adfp = ActiveDocument.FilePathActiveDocument.SaveAsCopy adfp & "DOCUMENT_" & Format(X, "0000000000") & ".cdr" '173.9551, 190.8633, 188.7539, 187.5313