![]() |
#1
|
|||
|
|||
![]()
Hi all,
sometimes, when I open documents with my script, Corel shows me a messagebox like "This file is corrupted". Script is blocked until I press the OK button and all operations continue normally. So, how can I intercept these events and press the correct button (ok if there's only one or a different one if there are many buttons) ? Thanx Damiano |
#2
|
||||
|
||||
![]()
Damiano,
Unfortunately I don't know of a way to dismiss a message box from a macro. That's because once the message box appears, the macro stops execution until the dialog is dismissed. However if you create a stand-alone program that would just monitor system for presence of the message box window and send "Enter" keystroke to it, that might do it. The bad thing is that you'll need to use a stand-alone Visual Basic or C++ compiler to produce the EXE that will run in background and perioudically scan through all open windows trying to locate the annoying message box. One thing to try is to use SendKeys method in VBA just before opening a file: Code:
SendKeys "{ENTER}", False
Set doc = OpenDocument("C:\Temp\SomeCorruptFile.cdr")
DoEvents
I haven't tried this myself but just a guess that this might work. Sorry if it doesn't... |
#3
|
||||
|
||||
![]()
Ok, the above code doesn't work but I have good news. I found the way to dismiss the dialog from VBA.
The idea is to set up a timer through Windows API which will call a VBA function every, say, 2 seconds. If the CDR file opens up quickly, the function never gets called and everything behaves as before. However if the message box appears during opening the file, the macro pauses and after 2 seconds of suspension, the function gets called which uses SendKeys to close the message box and the macro execution continues. Here is how you do it in VBA: Code:
Option Explicit
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Sub TestCloseMessage()
Dim doc As Document
Dim nId As Long
nId = SetTimer(0, 100, 2000, AddressOf KillMessageCallback)
Set doc = OpenDocument("C:\Temp\SomeCorruptFile.cdr")
KillTimer 0, nId
End Sub
Private Sub KillMessageCallback()
SendKeys "{ENTER}", False
End Sub
1. Just before opening a document, I set up a system timer using Windows API function SetTimer. The third parameter (2000) is the interval in milliseconds to call the function specified in the next parameter (KillMessageCallback). So, in the above example, the function will be called every 2 seconds. You can fine tune this value if you are opening large files which usually takes more than 2 seconds to open. 2. The file is being open. 3. If it opens up quickly, then the timer is destroyed before KillMessageCallback is ever called. However if OpenDocument takes more than 2 seconds to open (maybe because it stopped due to the message box), then KillMessageCallback is called which sends the Enter key stroke to the message box which just closes it. It seems to work on my machine. Hopefully it will work on yours as well. I hope this helps. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Closing curves | ddonnahoe | CorelDRAW/Corel DESIGNER VBA | 9 | 27-04-2004 10:17 |
Copying objects to clipboard then closing document. | CORNMEN | CorelDRAW/Corel DESIGNER VBA | 4 | 31-03-2003 09:52 |
Cyrillic fonts from inputBox | Dino | CorelDRAW/Corel DESIGNER VBA | 0 | 26-03-2003 10:39 |
closing dockers/interactive toolbars to speed up a macro | Rick Randall | CorelDRAW CS | 1 | 09-12-2002 20:39 |