PC Review


Reply
Thread Tools Rate Thread

Automatically Selecting "Yes" in an Externally Called Message Box

 
 
IComeInTheWest@gmail.com
Guest
Posts: n/a
 
      13th Aug 2007
Hello,

I am writing a macro that opens a workbook (say, MyWorkbook) and calls
a macro (say, MyMacro) from MyWorkbook. MyMacro displays a vbYesNo
message box in which I'd like to select "Yes" automatically.

One idea I was given (with a caveat of method-unreliability) was to
use the SendKeys Method as follows:

Application.SendKeys "{RETURN}"
Application.Run "MyWorkbook!MyMacro"

I tried this and it worked the first few times but has not worked the
previous few.

Why is the SendKeys Method so quirky?

Is there another, better way to automatically select "Yes" in a
message box which was called from another workbook?

Note: Editing the code in MyMacro is not an option.

Regards,

Calvin

 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      13th Aug 2007
SendKeys is unreliable because it writes to the active window. If your
dialog pops up behind the active window, or if there's a delay in its
appearance, you will be sending keystrokes to the wrong window.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I am writing a macro that opens a workbook (say, MyWorkbook) and calls
> a macro (say, MyMacro) from MyWorkbook. MyMacro displays a vbYesNo
> message box in which I'd like to select "Yes" automatically.
>
> One idea I was given (with a caveat of method-unreliability) was to
> use the SendKeys Method as follows:
>
> Application.SendKeys "{RETURN}"
> Application.Run "MyWorkbook!MyMacro"
>
> I tried this and it worked the first few times but has not worked the
> previous few.
>
> Why is the SendKeys Method so quirky?
>
> Is there another, better way to automatically select "Yes" in a
> message box which was called from another workbook?
>
> Note: Editing the code in MyMacro is not an option.
>
> Regards,
>
> Calvin
>



 
Reply With Quote
 
IComeInTheWest@gmail.com
Guest
Posts: n/a
 
      13th Aug 2007
On Aug 13, 4:34 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> SendKeys is unreliable because it writes to the active window. If your
> dialog pops up behind the active window, or if there's a delay in its
> appearance, you will be sending keystrokes to the wrong window.
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> <IComeInTheW...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Hello,

>
> > I am writing a macro that opens a workbook (say, MyWorkbook) and calls
> > a macro (say, MyMacro) from MyWorkbook. MyMacro displays a vbYesNo
> > message box in which I'd like to select "Yes" automatically.

>
> > One idea I was given (with a caveat of method-unreliability) was to
> > use the SendKeys Method as follows:

>
> > Application.SendKeys "{RETURN}"
> > Application.Run "MyWorkbook!MyMacro"

>
> > I tried this and it worked the first few times but has not worked the
> > previous few.

>
> > Why is the SendKeys Method so quirky?

>
> > Is there another, better way to automatically select "Yes" in a
> > message box which was called from another workbook?

>
> > Note: Editing the code in MyMacro is not an option.

>
> > Regards,

>
> > Calvin- Hide quoted text -

>
> - Show quoted text -


Is there a logical way to determine in which window a dialog box will
appear?

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      13th Aug 2007
It would be better to suppress the display of the msgbox.

If it is produced by event code in the other workbook

Application.EnableEvents = False
set bk = Workbooks.Open("C:\Myfolder\Myboooks.xls")
' process the book
bk.Close SaveChanges:=False
Application.EnableEvents = True


--
Regards,
Tom Ogilvy


"(E-Mail Removed)" wrote:

> On Aug 13, 4:34 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
> wrote:
> > SendKeys is unreliable because it writes to the active window. If your
> > dialog pops up behind the active window, or if there's a delay in its
> > appearance, you will be sending keystrokes to the wrong window.
> >
> > - Jon
> > -------
> > Jon Peltier, Microsoft Excel MVP
> > Tutorials and Custom Solutions
> > Peltier Technical Services, Inc. -http://PeltierTech.com
> > _______
> >
> > <IComeInTheW...@gmail.com> wrote in message
> >
> > news:(E-Mail Removed)...
> >
> >
> >
> > > Hello,

> >
> > > I am writing a macro that opens a workbook (say, MyWorkbook) and calls
> > > a macro (say, MyMacro) from MyWorkbook. MyMacro displays a vbYesNo
> > > message box in which I'd like to select "Yes" automatically.

> >
> > > One idea I was given (with a caveat of method-unreliability) was to
> > > use the SendKeys Method as follows:

> >
> > > Application.SendKeys "{RETURN}"
> > > Application.Run "MyWorkbook!MyMacro"

> >
> > > I tried this and it worked the first few times but has not worked the
> > > previous few.

> >
> > > Why is the SendKeys Method so quirky?

> >
> > > Is there another, better way to automatically select "Yes" in a
> > > message box which was called from another workbook?

> >
> > > Note: Editing the code in MyMacro is not an option.

> >
> > > Regards,

> >
> > > Calvin- Hide quoted text -

> >
> > - Show quoted text -

>
> Is there a logical way to determine in which window a dialog box will
> appear?
>
>

 
Reply With Quote
 
IComeInTheWest@gmail.com
Guest
Posts: n/a
 
      13th Aug 2007
On Aug 13, 5:40 pm, Tom Ogilvy <TomOgi...@discussions.microsoft.com>
wrote:
> It would be better to suppress the display of the msgbox.
>
> If it is produced by event code in the other workbook
>
> Application.EnableEvents = False
> set bk = Workbooks.Open("C:\Myfolder\Myboooks.xls")
> ' process the book
> bk.Close SaveChanges:=False
> Application.EnableEvents = True
>
> --
> Regards,
> Tom Ogilvy
>
>
>
> "IComeInTheW...@gmail.com" wrote:
> > On Aug 13, 4:34 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
> > wrote:
> > > SendKeys is unreliable because it writes to the active window. If your
> > > dialog pops up behind the active window, or if there's a delay in its
> > > appearance, you will be sending keystrokes to the wrong window.

>
> > > - Jon
> > > -------
> > > Jon Peltier, Microsoft Excel MVP
> > > Tutorials and Custom Solutions
> > > Peltier Technical Services, Inc. -http://PeltierTech.com
> > > _______

>
> > > <IComeInTheW...@gmail.com> wrote in message

>
> > >news:(E-Mail Removed)...

>
> > > > Hello,

>
> > > > I am writing a macro that opens a workbook (say, MyWorkbook) and calls
> > > > a macro (say, MyMacro) from MyWorkbook. MyMacro displays a vbYesNo
> > > > message box in which I'd like to select "Yes" automatically.

>
> > > > One idea I was given (with a caveat of method-unreliability) was to
> > > > use the SendKeys Method as follows:

>
> > > > Application.SendKeys "{RETURN}"
> > > > Application.Run "MyWorkbook!MyMacro"

>
> > > > I tried this and it worked the first few times but has not worked the
> > > > previous few.

>
> > > > Why is the SendKeys Method so quirky?

>
> > > > Is there another, better way to automatically select "Yes" in a
> > > > message box which was called from another workbook?

>
> > > > Note: Editing the code in MyMacro is not an option.

>
> > > > Regards,

>
> > > > Calvin- Hide quoted text -

>
> > > - Show quoted text -

>
> > Is there a logical way to determine in which window a dialog box will
> > appear?- Hide quoted text -

>
> - Show quoted text -


Tom,

Thanks for the idea. I'm not sure if that will work, however, because
the dialog box in question has "Yes" and "No" buttons which route the
procedure to different places. I'd like to automatically select "Yes".

Regards,

Calvin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting "New message" makes Outlook hang: "Not responding" =?Utf-8?B?R2VydA==?= Microsoft Outlook Discussion 2 22nd Nov 2006 09:42 PM
OL2000: Selecting "send page by e-mail" or "send link by e-mail" in Internet Explorer locks Outlook until message is sent =?iso-8859-2?Q?Ivan_B=FAtora?= Microsoft Outlook Discussion 0 31st Mar 2005 04:46 PM
OL2000: Selecting "send page by e-mail" or "send link by e-mail" in Internet Explorer locks Outlook until message is sent =?iso-8859-2?Q?Ivan_B=FAtora?= Microsoft Outlook Discussion 0 31st Mar 2005 04:38 PM
Error copying with "...file has been externally altered" message BB Windows XP General 0 8th Sep 2004 09:57 PM
error message: "pure virtual function called" =?Utf-8?B?QnJ1Y2U=?= Microsoft Powerpoint 1 18th Feb 2004 03:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:26 PM.