I need help getting this started.
This is probably simpler than I'm thinking it is. Or not? We'll see... This is my attempt to add onto what I've already had going. I have community discussion where I'm using a .txt file to name my Corel Documents. This part is done and works well.
Now that my documents are created and saved. I want to duplicate everything that is on Page1 & 2 to a new Document (Pages 1 & 2). I might figure out the rest like using my .txt file to name the new duplicated document.
I just need help getting the items over to the correct page.
Recap:
Can you help? I do, however, need to utilize the code below, though. Because every new document must be named with a new number. I just need all it's contents copied over to the new document (page 1 & 2) and possibly (but not necessary) it's metadata.
Here is the code used from my previous discussion.
Just run this code after you do the highlight below w/Corel open. It will create a New Document and Add a Number as Document Name. But first you have to save the text file somewhere and save a number inside it.
Sub newDesignNumber()
Dim TextFile As IntegerDim FilePath As StringDim FileContent As String
'----------------------------------------------------------------- Folder Path
On Error Resume NextFilePath = "N:\Logo Database\Design Number" & ".txt" ' < Create a new txt file and start with a number ex: 200 save on desktop and save path here.
'----------------------------------------------------------------- Get String (Proof Number) From Text File.
TextFile = FreeFile
On Error GoTo ErrHandler
Open FilePath For Input As TextFileLine Input #TextFile, FileContentClose #TextFile
'------------------------------------------------- Opens New Document & Adds Pages
Dim doc1 As DocumentSet doc1 = CreateDocument()doc1.Name = FileContent + 1
'------------------------------------------------- Stores New Proof Number
Open FilePath For Output As TextFileOn Error Resume NextPrint #TextFile, ActiveDocument.NameClose TextFile
Optimization = True
'------------------------------------------------- Adds Pages to Document
Dim p1 As PageSet p1 = ActiveDocument.InsertPagesEx(1, False, ActivePage.Index, 8.5, 11#)p1.Activatep1.Name = "Proof"Dim p2 As PageSet p2 = ActiveDocument.InsertPagesEx(1, False, p1.Index, 8.5, 11#)p2.Activatep2.Name = "CutFile"ActiveDocument.Pages(1).ActivateActivePage.Name = "Mat" '------------------------------------------------- Opens Metadata Form'saveMetaData.Show vbModeless'------------------------------------------------
ExitSub:Optimization = FalseActiveWindow.RefreshApplication.RefreshActiveDocument.EndCommandGroupExit Sub ErrHandler:MsgBox "Something Went Wrong..." & vbCr & "Error occured: " & Err.DescriptionResume ExitSub
End Sub
Why duplicate two pages, when you can delete the extra ones and save the document under a different name?
Good question. So, when my customer requests a change to design number 4444 and asks to make the background Red instead of Blue. I will reference design 4444 - Create a new design, make the color change (but in order to do that i need everything from 4444 to copy over to the new design document). I have page 1 for the "mat" and Page 2 for the proof. I need both to carry over (along with metadata if possible).
Well... I don't think I had a choice in this case? See - There are 3 of us Designers. Each of us needs to create a new document with the next 'design number' in line (stored on the txt file). IF Designer 1's last document number as 4444 and the next artist creates a new document it will be 4445 and will keep counting up. We all use the TXT file (which is saved on our server.) We run the macro and it names the document with the last stored number on the file. I have no other way to make this work for all 3 of us. Basically, it started with design# 1 and now we are on design# 4444. This is how we name our documents and how we track designs. Also, how customers reference the designs and what they sign off on when they are approved. So we have no choice but to be dependent on it?
I know of no other way? I can see your method working if it were just me but it's not. We all need to know what the very last number is to create the next design.
CDT said: We run the macro and it names the document with the last stored number on the file.
And what is your question? Your macro accesses the server, gets the last file number from there and creates a new document with the following number. Such a macro can be tied to the Create_Document event, in order not to start it manually
Maybe they creates documents for other purpose, for spot/personal use... I would use an add-in having an option to name the document..
It is not really impossible even not so probable that simultaneously two persons trying to name the document will receive the same number and I would suggest to find a code workaround for such cases. For instance when you save the document, that add-in to have the possibility to catch the Document BeforeSave event and in such a case to ask for a name modification. Something like adding 'bis 'or '.a' at the name end. If the name is only numeric to evaluate that and rise the event only in case of the appropriate document. I mean you can name them Test00001, Test00123 and you can find a way to identify this range for documents being saved with the initial purpose...
FaneDuru said:It is not really impossible even not so probable that simultaneously two persons trying to name the document will receive the same number and I would suggest to find a code workaround for such cases.
I think that macro can simply open file with the lock from other users. Something like
Open "Numbers.txt" For Binary Access Read Write Lock Read Write As #FileNum
And what would it happen if simultaneous with the first an other user will try to obtain the next number for naming his document?
Will he receive an error denying access to the file? Is that a good solution? Procedurally speaking...
Maybe the opening for Read Write will be inside of a short Loop of a second between On error Resume Next and On error GoTo 0...
Yes, there will be a sharing error and the macro will have to wait until the first user finishes working with this file.
We have not had any issues w/us all trying to access the same number at the same time. Not yet anyway. I do believe it shows a sharing error. I've only seen it once. Perhaps if we had more than 3 people using the file - it might be more of an issue. But it seems to work exactly as I need it to. It does what it should be doing!
I simply wanted to add to it. Efficiency reasons... I'm a logo production artist. I have to work quick! I simply wanted to use my macro code above BUT integrate the copy method into it. I wanted to Open and Existing Document. Run my code. Have it create a New Doc w/Number from txt file. Inserts my 3 layers and copy all the content from the opened Document over to my new document. So I didnt have to do it manually. That's all I wanted direction on.
Open document
Modify
SaveAs
https://community.coreldraw.com/sdk/api/draw/20/m/document.saveas
Close document
That's it!!! That's exactly what I needed I had to make one small change but worked like a charm. Thank you so much!
Also, genius. I'm not sure why save as didn't register with me earlier. So much faster! appreciate all the help everyone :)