OberonPlace.com Forums  

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

Thread Tools Search this Thread Display Modes
Old 25-03-2003, 05:36
Posts: n/a
Default Closing MessageBox or InputBox

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) ?

Reply With Quote
Old 15-04-2003, 09:24
Alex's Avatar
Alex Alex is offline
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Closing MessageBox or InputBox


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:

SendKeys "{ENTER}", False
Set doc = OpenDocument("C:\Temp\SomeCorruptFile.cdr")
Hopefully what this will do is just send the Enter key stroke to CorelDRAW message queue and it will stay there until CorelDRAW is free to process messages. Then if OpenDocument causes the message box to appear, the Enter keystroke arrives from the queue and effectively "clicks" the OK button. If there is no message box, then the following DoEvents command will just process the Enter key in the queue and do nothing.

I haven't tried this myself but just a guess that this might work. Sorry if it doesn't...
Reply With Quote
Old 15-04-2003, 09:38
Alex's Avatar
Alex Alex is offline
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Closing MessageBox or InputBox

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:

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
What happens here is the following:

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.
Reply With Quote

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

All times are GMT -5. The time now is 05:14.

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