OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 15-08-2010, 12:16
gag546112
Guest
 
Posts: n/a
Default Having a bit of a timing issue

Hi,
I'm using Corel Draw X4.

I have automated the manipulation of a CDR template out of MS Access and seem to be having a timing issue on one computer, but not others.

Here is the code:

Quote:
Dim oApp As Object, oDoc As CorelDRAW.Document, oShape As CorelDRAW.Shape, oText As CorelDRAW.Text

'Open Polarity Chart
Set oApp = CreateObject("CorelDraw.Application.14")
Set oDoc = oApp.CreateDocumentFromTemplate(DirectoryPath & "\" & cPolarityChartFileName)

'Set Properties of Polarity Chart

oApp.Visible = True
oDoc.ClearSelection
oDoc.ActivePage.Layers("Graphics").Activate

For i = 1 To NumOfSegments ' Process colours for segments.
oDoc.ActivePage.Shapes(ColorText(i, 1)).Fill.ApplyUniformFill oApp.CreateRGBColor(ColorText(i, 8), ColorText(i, 9), ColorText(i, 10))
oDoc.ClearSelection
Next

When this code executes, I get the following error message:

"-2147024809: Layer "Graphics" not found"

The Graphics layer is definitely there, because, as I mentioned, this works perfectly on a different computer. So, I commented out the 'Layer.Activate' line and tried again. This time I got a different error message:

"-2147467259: The specified object is not found"

This error occurs on the 3rd from last line of code in the sample. The "ColorText(i, 1)" code is simply reading the shape name from an array.

The interesting thing is, if I put a breakpoint at either of these lines of code and then click the Run button in the Access debugger, everything works fine. This leads me to think that I have a timing issue. For example, maybe Corel Draw isn't ready for my code execution because its still busy sorting itself out after creating the document from a template. So, I declared the kernel sleep API and added a 5 second delay after creating the new document.

Sadly, still no joy.

Does anyone have any clues for me??

Thanks in advance,

George
Reply With Quote
  #2  
Old 15-08-2010, 13:25
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default

Hi,

Try multiple Sleep() calls in a loop with a DoEvents alongside each. Just calling Sleep() does not let VBA finishing anything it still needs to do.

-James
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
  #3  
Old 15-08-2010, 20:58
gag546112
Guest
 
Posts: n/a
Default

Thanks James. I'll give that a try on Monday and report back.

George
Reply With Quote
  #4  
Old 18-08-2010, 16:06
SteveDude SteveDude is offline
Senior Member
 
Join Date: Dec 2005
Location: Salina, Kansas USA
Posts: 149
Default ...

I always check for the state of the Corel Window via API, using FindWindow, IsIconic, IsVisble and adjust accordingly. This one got me, because the class name changed for the first time ever since v1.0 in the X5 service pack 1, so I now check for them with possible future SP's...

Code:
For i = 4 to 0 Step-1
     hwCorel = FindWindow("CorelDRAW 15." & Cstr(i), vbNullString)
     If hwCorel <> 0 Then
       If IsIconic(hwCorel) Then ShowWindow(hwCorel, SW_NORMAL)
       Exit For
    End If
Next i
You can also put it in a While Loop, just give yourself a way out of it if things take too long...or after you have a valid handle do the loop until the window is visible.

Last edited by shelbym; 18-08-2010 at 16:46. Reason: Fixed Code Tag
Reply With Quote
  #5  
Old 21-08-2010, 09:02
gag546112
Guest
 
Posts: n/a
Default

James,
I gave your idea a try but still no joy. I'm going to get time to experiment a bit more with it on Sunday, probably trying even longer delays. But I feel that there is something else involved here.

I'll add another post after Sunday.

George

Last edited by gag546112; 21-08-2010 at 09:07.
Reply With Quote
  #6  
Old 21-08-2010, 09:07
gag546112
Guest
 
Posts: n/a
Default

SteveDude,
Thanks for this suggestion. I'll give this a try on Sunday as well.

Can I take it that the Corel Draw window has to be visible in order for the VBA code running in MS Access to be executable?

Regards,

George
Reply With Quote
  #7  
Old 22-08-2010, 08:36
gag546112
Guest
 
Posts: n/a
Default

Now I feel a bit embarrassed!!

I inadvertently put the time delay before the "oApp.Visible = True" statement, instead of after it. Once I fixed that, I found that a one second delay was sufficient to allow the Corel Draw X4 window to appear.

Everything now working great.

Thanks for your suggestions. Its good to know that there are folks like the two of you out there to offer us novices assistance when we need it.

George
Reply With Quote
  #8  
Old 22-08-2010, 18:26
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default

Hi George,

It has happened to all of us. I am glad that you are able to move forward with your project.

-James
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PMS color - X5 Issue biok CorelDRAW/Corel DESIGNER VBA 4 29-04-2010 13:52
Eraser issue jahmer General 0 17-01-2008 15:59
SetSize issue Dave Rowland CorelDRAW/Corel DESIGNER VBA 3 11-01-2008 16:36
weird font issue bbolte CorelDRAW/Corel DESIGNER VBA 1 21-04-2005 15:20
Thumbnailer Issue with EPS files vallentin Macros/Add-ons 2 16-03-2004 10:04


All times are GMT -5. The time now is 10:54.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com