Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Answering message box with visual basic statement

  Asked By: Cory    Date: Feb 15    Category: MS Office    Views: 2785
  

I want to run 100 data cases each for 5 minutes on an IP software
(Frontline Premium solver). I wrote a code in VBA to call this
software for each of the data cases and run them for five minutes.
After running each case for five minutes, a message box pops up
(because of software) asking me whether I want to stop this case now
or keep improving the solution to optimal value (which may take
hours). If I answer this by clicking the message box, I will have to
be in front of my laptop for 9 hours clicking every five minutes. I
will like to answer this message box with the help of visual basic
command. Otherwise, is there a way to avoid any message box poping up
itself. (if message box does not pop up, software may take my default
answer "stop this case").

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Teresa Rogers     Answered On: Feb 15

Long shot this, since I don't know anything about Frontline, but how
about the line
application.DisplayAlerts=False

 
Answer #2    Answered By: Tammy Sanders     Answered On: Feb 15

Unfortunately, messagebox still pops up even after writing
application.DisplayAlerts=False
Can you suggest something else?

 
Answer #3    Answered By: Hilma Miller     Answered On: Feb 15

Because this is an external application, you want to send keystrokes
(specifically Tabs and Enter commands) to the external program.

AS A LAST RESORT (according to my resident expert programmer Peter G), you can
use SendKeys from VBA.

Issue with special characters is that you need to enclose them in curly
brackets, or something like that. E.g. Sendkeys({Tab}) - don't quote me.

Lastly, since the message  box is from an external program, VBA will not know
when it appears. So now you have to synchronise time (which in your application
should be easy to do - Start solver, wait for 5.5 minutes, then send
keystrokes), and then repeat.

If SendKeys does not do it for you, perhaps search on Google Newsgroups for
"Sendkeys Alternative".

We did this a few years a go with SendKeys and an external model, and it was
messy.

 
Answer #4    Answered By: Earl Stone     Answered On: Feb 15

If the messagebox always has the same title (or not always the same, but
something you can predict), you could use AppActivate to check if it exists. In
conjunction with OnTime and SendKeys, you could frequently try to activate the
app with that window (messagebox) open. If it can activate it, then use SendKeys
to send an Enter.

Here is a simple example. Copy the following VBA code into a module in Excel.
Launch MS Word and select File >> Save As. Switch back to Excel and run  the
SendEnter1 macro. As long as cell A1 on Sheet1 is empty, it will try to activate
the Save As window in Word every 10 seconds. If it succeeds, it sends Enter,
which closes the Save As dialog. If it fails (because there is no Save As dialog
present), it send no keystrokes and starts another 10-second countdown. If you
select File >> Save As in Word, within 10 seconds the macro will close it.

Public Sub SendEnter1()
'Call SendEnter2 10 seconds later.
Application.OnTime Now + TimeValue("00:00:10"), "SendEnter2"
End Sub

Private Sub SendEnter2()
'Try to switch to the application with a "Save As" window open.
On Error GoTo DoMore
AppActivate "Save As"
'If we were able to activate the desired app, call SendEnter3
'one second from now.
Application.OnTime Now + TimeValue("00:00:01"), "SendEnter3"
DoMore:
DoEvents
'Quit when anything is entered in A1 on Sheet1 of this workbook.
If Len(ThisWorkbook.Sheets("Sheet1").Range("A1").Value) = 0 Then
'Otherwise, call SendEnter1 to start the proess over again.
Call SendEnter1
End If
End Sub

Private Sub SendEnter3()
'Send an Enter keystroke.
Application.SendKeys "~"
End Sub

 
Answer #5    Answered By: Anna Hill     Answered On: Feb 15

I could not succeed. I am not able to clearly understand usage of
SendKeys.

Software pops up with following message  box at the end of each run

Continue Stop Restart Exit

The cursor's position is at "Continue". I need to select "Stop". If
I personally enter the keys, I will have to press first TAB and then
ENTER. Therefore, I tried giving following commands
Application.SendKeys "TAB", True
Application.SendKeys "ENTER", True

I was not successful. So I tried giving
SendKeys "TAB", True
SendKeys "ENTER", True
I was not successful. If I could not correct it, I will spend my
weekends entering Stop every 10 minutes 100 times or more
physically.

 
Answer #6    Answered By: Alexander Fields     Answered On: Feb 15

Try SendKeys "{TAB}{EMYER}"

"{ENTER}" is the same as "~"

You must enclose special characters like tab, escape, cursor left, etc. in
curly braces {}. If you type SendKeys in the VBA Editor and press F1 do you
get the help information for the SendKeys fundtion? It tells you all that
stuff.

 
Answer #7    Answered By: Vivian Ruiz     Answered On: Feb 15

Unfortunately, I did not get any success................

 
Answer #8    Answered By: Harold Graham     Answered On: Feb 15

Well, let's keep trying.

If I'm in Word, and I want to send the word "hello" to Excel, I can use:



Sub SendThem

AppActivate "Microsoft Excel"

DoEvents

SendKeys "hello"

End Sub



For me, this brings up Excel and types "hello" wherever I am in Excel,
whether that's in a cell or a dialog box  or whatever happens to be open.



One key here is the DoEvents call -- this allows Windows to actually give
the other app the focus BEFORE doing the SendKeys, otherwise, it just sends
"hello" to my own app (Word).



Does the addition of DoEvents help at all?

 
Answer #9    Answered By: Giovanna Silva     Answered On: Feb 15

Thanks for your kind help but I have decided to just continue
clicking "stop" by mouse for each of the 100-200 cases. I will just
spend next 3 days doing that.

 
Answer #10    Answered By: Aaliyah Khan     Answered On: Feb 15

We know where you'll be if anyone wants to reach you -- tied to
your computer keyboard! Sorry we couldn't get it quite set into place.

 
Didn't find what you were looking for? Find more on Answering message box with visual basic statement Or get search suggestion and latest updates.




Tagged: