Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default how to Pause a VBA procedure until user presses Enter

Is there a way to suspend execution of a VBA procedure until the user takes
a specific action like pressing the Enter key?

Thanks in advance,

Paul


  #2   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default how to Pause a VBA procedure until user presses Enter

Only with some kind of InputBox or MessageBox.

--

Vasant

"Paul James" wrote in message
...
Is there a way to suspend execution of a VBA procedure until the user

takes
a specific action like pressing the Enter key?

Thanks in advance,

Paul




  #3   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default how to Pause a VBA procedure until user presses Enter

You could put a loop in the middle of your code and check for the desired
specific action to exit the loop.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications

www.pcdatasheet.com

"Paul James" wrote in message
...
Is there a way to suspend execution of a VBA procedure until the user takes
a specific action like pressing the Enter key?

Thanks in advance,

Paul




  #4   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default how to Pause a VBA procedure until user presses Enter

Thanks for the reply, Vasant - Message Boxes won't work because I'm trying
to enable the user to perform some actions before the code resumes. With a
message box, the user can't perform any actions other than click a button on
the message box to make it go away, but then the code resumes as soon as the
message box closes, so I will have accomplished nothing.

With an Input Box, the same limitations prevail, except that you get to type
some text in the Input Box. Unfortunately, I need for the user to type more
than a small string of text. Sometimes several sentences. But again, I
want those sentenced typed at a very specific context, namely in the middle
of a procedure that does other specific things before and after the user
types those sentences.

Any ideas how to accomplish this?

Paul


  #5   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default how to Pause a VBA procedure until user presses Enter

Thanks for your reply, PC.

I suppose I should have mentioned that I'd like the user to be able to do
some things in the host application while the VBA code is paused.
Specifically, type some data. (Input Boxes and Message Boxes won't work for
this, as I explained elsewhere in this threat).

If I create a loop that runs until the user takes some action, such as press
the Enter key, which is what I would like, the running VBA loop prevents the
user from doing anything else. So my user wouldn't be able to do anything,
and thus, nothing is accomplished.

In effect, I'd like to somehow momentarily interrupt (pause) execution of
the VBA code, while the user types several sentences of text, and then
resume the VBA code as soon as the user presses the Enter key.

Any ideas?

TIA




  #6   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how to Pause a VBA procedure until user presses Enter

You most certanly can do this with a form...

Check out:

http://www.attcanada.net/~kallal.msn/Dialog/Index.html

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

http://www.attcanada.net/~kallal.msn


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default how to Pause a VBA procedure until user presses Enter

Paul,

Can you not run the procedure and at the end prompt the
user to type the info into whichever cells and also set
the Enter key to run a second procedure using the OnKey
method? The second procedure would continue where the
first left off. At the end of the second procedure you
could reset the Enter key to normal using OnKey.

Alternatively, have the one procedure branch dependant on
the value of a module level or static variable. If the
variable equals 0 then run the first part and set it to 1
at the end of the first part. Then when the same procedure
is run again (by pressing the Enter key) it will run the
second part of the procedure. At the end of the second
part set the variable back to 0 and reset the Enter key to
normal.

Regards,
Greg


-----Original Message-----
Thanks for your reply, PC.

I suppose I should have mentioned that I'd like the user

to be able to do
some things in the host application while the VBA code is

paused.
Specifically, type some data. (Input Boxes and Message

Boxes won't work for
this, as I explained elsewhere in this threat).

If I create a loop that runs until the user takes some

action, such as press
the Enter key, which is what I would like, the running

VBA loop prevents the
user from doing anything else. So my user wouldn't be

able to do anything,
and thus, nothing is accomplished.

In effect, I'd like to somehow momentarily interrupt

(pause) execution of
the VBA code, while the user types several sentences of

text, and then
resume the VBA code as soon as the user presses the Enter

key.

Any ideas?

TIA


.

  #8   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how to Pause a VBA procedure until user presses Enter

If you use Application.Inputbox, this operates in a way that allows further
action.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Paul James" wrote in message
...
Thanks for the reply, Vasant - Message Boxes won't work because I'm trying
to enable the user to perform some actions before the code resumes. With

a
message box, the user can't perform any actions other than click a button

on
the message box to make it go away, but then the code resumes as soon as

the
message box closes, so I will have accomplished nothing.

With an Input Box, the same limitations prevail, except that you get to

type
some text in the Input Box. Unfortunately, I need for the user to type

more
than a small string of text. Sometimes several sentences. But again, I
want those sentenced typed at a very specific context, namely in the

middle
of a procedure that does other specific things before and after the user
types those sentences.

Any ideas how to accomplish this?

Paul




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to Pause a VBA procedure until user presses Enter

I remember reading somewhere that it's not possible to pause a macro
The solution for this is, as mentioned before, to make a loop and ru
it until the user does something..

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default how to Pause a VBA procedure until user presses Enter

Explaining further Albert's amd van's responses, create a pop-up form and open
it with code like this:
DoCmd.OpenForm "YourForm",,,,,acDialog

A button on your pop-up form then needs to make the form not visible. Clicking
this button will then cause the code following the OpenForm statement to resume.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications

www.pcdatasheet.com


"Paul James" wrote in message
...
Thanks for your reply, PC.

I suppose I should have mentioned that I'd like the user to be able to do
some things in the host application while the VBA code is paused.
Specifically, type some data. (Input Boxes and Message Boxes won't work for
this, as I explained elsewhere in this threat).

If I create a loop that runs until the user takes some action, such as press
the Enter key, which is what I would like, the running VBA loop prevents the
user from doing anything else. So my user wouldn't be able to do anything,
and thus, nothing is accomplished.

In effect, I'd like to somehow momentarily interrupt (pause) execution of
the VBA code, while the user types several sentences of text, and then
resume the VBA code as soon as the user presses the Enter key.

Any ideas?

TIA






  #11   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to Pause a VBA procedure until user presses Enter

Thanks for the suggestion, Bob. However Application.InputBox still confines
you to entering any text in the InputBox without giving you the opportunity
to enter data elsewhere. I need more flexibility than that.


"Bob Phillips" wrote in message
...
If you use Application.Inputbox, this operates in a way that allows

further
action.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Paul James" wrote in message
...
Thanks for the reply, Vasant - Message Boxes won't work because I'm

trying
to enable the user to perform some actions before the code resumes.

With
a
message box, the user can't perform any actions other than click a

button
on
the message box to make it go away, but then the code resumes as soon as

the
message box closes, so I will have accomplished nothing.

With an Input Box, the same limitations prevail, except that you get to

type
some text in the Input Box. Unfortunately, I need for the user to type

more
than a small string of text. Sometimes several sentences. But again, I
want those sentenced typed at a very specific context, namely in the

middle
of a procedure that does other specific things before and after the user
types those sentences.

Any ideas how to accomplish this?

Paul






  #12   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default my thanks to Bob, Albert, Van and PC

You're right - a user form is the solution.

Duh.

Thanks, guys.


  #13   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default how to Pause a VBA procedure until user presses Enter

Hi Paul,

The following example should suit your requirements.

Regards,
Vic Eldridge


Sub Macro1()
'Do some stuff...
Range("A1") = "Macro1 Started"
'Re-map the 2 Enter keys.
Application.OnKey "{Enter}", "EnterKeyPress"
Application.OnKey "~", "EnterKeyPress"
End Sub

Sub EnterKeyPress()
'Reset the Enter keys to normal behaviour.
Application.OnKey "{Enter}"
Application.OnKey "~"
Macro2
End Sub

Sub Macro2()
'Do some more stuff...
Range("A1") = "Macro2 Started"
End Sub





"Paul James" wrote in message ...
Thanks for the suggestion, Bob. However Application.InputBox still confines
you to entering any text in the InputBox without giving you the opportunity
to enter data elsewhere. I need more flexibility than that.


"Bob Phillips" wrote in message
...
If you use Application.Inputbox, this operates in a way that allows

further
action.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Paul James" wrote in message
...
Thanks for the reply, Vasant - Message Boxes won't work because I'm

trying
to enable the user to perform some actions before the code resumes.

With
a
message box, the user can't perform any actions other than click a

button
on
the message box to make it go away, but then the code resumes as soon as

the
message box closes, so I will have accomplished nothing.

With an Input Box, the same limitations prevail, except that you get to

type
some text in the Input Box. Unfortunately, I need for the user to type

more
than a small string of text. Sometimes several sentences. But again, I
want those sentenced typed at a very specific context, namely in the

middle
of a procedure that does other specific things before and after the user
types those sentences.

Any ideas how to accomplish this?

Paul




  #14   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default how to Pause a VBA procedure until user presses Enter

I never would have thought of remapping the Enter key, then using the
remapping to start the remaining procedure. Very clever.

Thanks, Vic.

Paul


  #15   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default my thanks to Bob, Albert, Van and PC

You're right - a user form is the solution.

Not necessarily.
See my reply to your original post.

Regards,
Vic Eldridge


  #16   Report Post  
Posted to microsoft.public.access.formscoding,microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default my thanks to Bob, Albert, Van and PC

Vic - I've got a question about the solution of redefining the Enter key.

If all goes as expected, it should work fine. However, if the application
closes for any reason before the user presses the Enter key, thus restoring
the original definition, what happens the next time the Enter key is
pressed - does it return to the default definition?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Macro: Pause & ask user: "Are you sure you want to continue? RoBear! Excel Discussion (Misc queries) 6 March 13th 08 09:14 AM
Macro to pause for user input in dialog box kayabob Excel Discussion (Misc queries) 1 June 22nd 05 07:49 PM
Pause Macro to enter data in cell Frank Kabel Excel Programming 4 May 30th 04 10:56 PM
Pause Macro to enter data in cell Bob Phillips[_6_] Excel Programming 0 May 28th 04 04:41 PM
Pause macro for user cell address input Ed Haslam Excel Programming 2 September 18th 03 07:53 PM


All times are GMT +1. The time now is 05:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"