find out if page is created

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.

            corelApp.CreateDocument();
            // 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 screen
I 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:

    1
    2
    3
    4
    If Documents.count = 0 Then
           MsgBox "No document open..."
          Application.CreateDocument
    End If
    

    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";
                          corelApp.Application.CreateDocument();
                      }
          
          • 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:

            1
            2
            3
            If InStr(Application.AppWindow.Caption, "Welcome Screen") > 0 Then
                MsgBox "Kein Dokument aktiviert"
            End If
            

            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`:

            1
            2
            3
            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...