Hello,I have active document DOCUMENT_0000000001.cdrI need macro to save active document as DOCUMENT_0000000002.cdrEach run of macro SAVE_AS must save active document with name increased with 1 of active document.
Each activation of the macro should save the active document with the name of the active document incremented by 1.
So, if active document name is DOCUMENT_0000000199.cdr, SAVE_AS macro activation must save active document as DOCUMENT_0000000200.cdr
Greetings!
Whenever you are solving a programming problem, the first step is to break down the problem into smaller problems. For example, in your case:
First, we need to analyze the file name to obtain its numbering.lets break this too:use substring to get numeric part of string string - Substring in VBA - Stack Overflowconverting string to intHow to Convert String to Integer in VBA (With Examples) - Statology Second, how do we increment this numbering? Next, how do we generate the new name?CREATE 100 FILES - CorelDRAW and Corel DESIGNER API - Developer Area - CorelDRAW Community Finally, we save the document.Document.SaveAs method - Developer Area - CorelDRAW Community
Hello,Thank You very much, but not work!I hope to get a more practical working answer. Looking for one as my routines are quite slow. I think there are always better ways.Greetings!BGНадявам се да получа по-практичен работещ отговор. Търся такъв, тъй като моите процедури са доста бавни. Мисля си, че винаги има и по-добри начини.
The algorithm I use isFor x = 1 to 100SaveAs ActiveDocument.FullPath & "DOCUMENT_" & Leading zeros & x & ".cdr"Now I will explain in detail.I expect something betterGreetings!
These three command lines may prove useful in solving the problem.MsgBox ActiveDocument.FullFileNameMsgBox ActiveDocument.FileNameMsgBox ActiveDocument.FilePath
In my case returned strings are:G:\COREL_MACROS_FROM_INTERNET\CREATE_100_FILES\MASTER_DOCUMENT.cdrMASTER_DOCUMENT.cdrG:\COREL_MACROS_FROM_INTERNET\CREATE_100_FILES\
Now I create SavedAs document nameNext useful code fragment is:For X = 1 To 100'MsgBox Len(X)MsgBox String(10 - Len(X), "0") & XNext2 steps to final code are necessaryHere is code to generate file namesFor X = 1 To 100MsgBox ActiveDocument.FilePath & String(10 - Len(X), "0") & XNext
For X = 1 To 100'MsgBox Len(X)MsgBox ActiveDocument.FilePath & "DOCUMENT_" & String(10 - Len(X), "0") & X & ".cdr"NextFinal phase:I will create 20 files to spend timeFor X = 1 To 20'MsgBox Len(X)'MsgBox ActiveDocument.FilePath & "DOCUMENT_" & String(10 - Len(X), "0") & X & ".cdr"ActiveDocument.SaveAsCopy ActiveDocument.FilePath & "DOCUMENT_" & String(10 - Len(X), "0") & X & ".cdr"Next
It's better to use SaveAsCopy except SaveAs because SaveAsCopy is faster approximately x 2, I thinkGreetings!Thank You for listening. I hope someone writes better code for this job