How i can find out if the page is created. and the corel draw is not in start screen like picture?
I would like to create a new page in defined size and orientation.
// set units
corelApp.ActiveDocument.Unit = corelApp.ActiveDocument.Rulers.HUnits;
// set canvas size to laser table size
corelApp.ActiveDocument.ActivePage.SizeHeight = ySize;
corelApp.ActiveDocument.ActivePage.SizeWidth = xSize;
But this crashes when the corel is on start screenI need to find out if corel always open and ready with a plain new page.And if not i need to create this new page (ctrl + n)
Try the next way, please:
If Documents.count = 0 Then
MsgBox "No document open..."
You can stop the code or create a new document. You can iterate between the open documents and select the one you need, if you need a specific one...
this gives me this error.
The error is the result of the fact that ActiveDocument does not exist! How to check Pages property of a not existing document?
That's why I recommended to previously check if such a document exists. If there is a document, but the Welcomescreen is activated, your code should activate Documents(1), or a specific document if you need a specific one...
of course, now it works. I have unfortunately approached the whole thing wrong with the autocomplete.Thanks a lot
if (corelApp.Documents.Count == 0)
TB_Info.Text = "Kein Dokument vorhanden";
Theoretically, in a specific circumstance, the Welcome Screen may be activated, but a document to also be open and no activated...
In such a circumstance, your code will also rise an error, because of the same reason: No ActiveDocument.
Then, the next (VBA) code will overpass the situation:
If InStr(Application.AppWindow.Caption, "Welcome Screen") > 0 Then
MsgBox "Kein Dokument aktiviert"
Unfortunately, trying to activate the existing document `Documents(1).Activate` will crush Corel, at least 2020...
You can create a new document, like above, or stop the code and ask to the user to activate the necessary one.
But you can create a 'Document' variable and use it instead of `ActiveDocument`:
Dim doc As Document
Set doc = Documents(1)
doc.ActivePage.SizeHeight = ySize
And use 'doc' instead of 'ActiveDocument' in the rest of the code. Anyhow, it is better to use an object than selecting, activating...