A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

What is the equivalent in O2K vb to "Sleep()"?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 16th 07, 09:12 PM posted to microsoft.public.outlook.program_vba
StargateFan
external usenet poster
 
Posts: 48
Default What is the equivalent in O2K vb to "Sleep()"?

Went hunting in the archives and didn't find anything there or in the
help file relating to a "sleep" function. In other scripting
languages, just to give an example, you can type in something like

Sleep(10000) 'for 10 seconds
or even just
Sleep 10000

and the macro pauses for the length of time stated. How would one do
that in O2K vb, pls? Thanks. D

Ads
  #2  
Old December 17th 07, 02:40 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default What is the equivalent in O2K vb to "Sleep()"?

Outlook VBA is not a scripting language, nor is any other variant of VBA
code. In VBA you can use the Win32 API Sleep method, just be very careful to
make sure it's not an infinite sleep since the thread still has to process
Windows messages.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 2000 ' sleep for 2000 ms = 2 seconds

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFan" wrote in message
...
Went hunting in the archives and didn't find anything there or in the
help file relating to a "sleep" function. In other scripting
languages, just to give an example, you can type in something like

Sleep(10000) 'for 10 seconds
or even just
Sleep 10000

and the macro pauses for the length of time stated. How would one do
that in O2K vb, pls? Thanks. D


  #3  
Old December 17th 07, 05:25 PM posted to microsoft.public.outlook.program_vba
StargateFanFromWork
external usenet poster
 
Posts: 39
Default What is the equivalent in O2K vb to "Sleep()"?

"Ken Slovak - [MVP - Outlook]" wrote in message
...
Outlook VBA is not a scripting language, nor is any other variant of VBA
code. In VBA you can use the Win32 API Sleep method, just be very careful
to make sure it's not an infinite sleep since the thread still has to
process Windows messages.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 2000 ' sleep for 2000 ms = 2 seconds


Yes, that was impressed upon me very much by the very many messages in
response to this query in the archives. But there was no alternative given.
If need be, a looping mechanism or something that would have accomplished
the end result would have been fine. But did try this, both with and
without the "Private Declare" statement and I get an error message so either
I'm doing something wrong, or the syntax is incorrect.

Here's is the script:
***************************
Private Sub Application_Startup()
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep 2000 ' sleep for 2000 ms = 2 seconds

strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub
***************************

Whether or not the "Private Declare" line has been put in, either way the
vbe is brought up with "sleep" highlighted and the error:
"Sub of Function not defined."

Thanks.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFan" wrote in message
...
Went hunting in the archives and didn't find anything there or in the
help file relating to a "sleep" function. In other scripting
languages, just to give an example, you can type in something like

Sleep(10000) 'for 10 seconds
or even just
Sleep 10000

and the macro pauses for the length of time stated. How would one do
that in O2K vb, pls? Thanks. D



  #4  
Old December 17th 07, 05:41 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default What is the equivalent in O2K vb to "Sleep()"?

The declaration for the Sleep() API function, as with any similar API
declarations, should be placed at module level and not inside another
method. Move it to above any code procedures in that module.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
"Ken Slovak - [MVP - Outlook]" wrote in message
...
Outlook VBA is not a scripting language, nor is any other variant of VBA
code. In VBA you can use the Win32 API Sleep method, just be very careful
to make sure it's not an infinite sleep since the thread still has to
process Windows messages.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 2000 ' sleep for 2000 ms = 2 seconds


Yes, that was impressed upon me very much by the very many messages in
response to this query in the archives. But there was no alternative
given. If need be, a looping mechanism or something that would have
accomplished the end result would have been fine. But did try this, both
with and without the "Private Declare" statement and I get an error
message so either I'm doing something wrong, or the syntax is incorrect.

Here's is the script:
***************************
Private Sub Application_Startup()
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep 2000 ' sleep for 2000 ms = 2 seconds

strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub
***************************

Whether or not the "Private Declare" line has been put in, either way the
vbe is brought up with "sleep" highlighted and the error:
"Sub of Function not defined."

Thanks.


  #5  
Old December 17th 07, 06:01 PM posted to microsoft.public.outlook.program_vba
StargateFanFromWork
external usenet poster
 
Posts: 39
Default What is the equivalent in O2K vb to "Sleep()"?

"Ken Slovak - [MVP - Outlook]" wrote in message
...
The declaration for the Sleep() API function, as with any similar API
declarations, should be placed at module level and not inside another
method. Move it to above any code procedures in that module.


Okay, though I understand the words individually, didn't understand all that
above g. What I did get out of that was to put it at the very top of the
"module", so I put this line which seemed to be most logical pat to put at
the very top:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' This line is so that you can use "Sleep" in any macro.


Then I changed the macro to this:
********************************************
Private Sub Application_Startup()
Sleep 2000 ' sleep for 2000 ms = 2 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub
********************************************
I even tried 5000 for 5 seconds. But it's still not behaving as it should.
The problem is that the box for this macro comes up on the heels of the
prompt to enable/disable macros. All the sleep does is delay that
enable/disable box from disappearing so that this box is _still_ being
called up on the heels of the other one's disappearance. Can we fine-tune
this to something more logical? What is needed is that _after_ the
disable/enable macros prompt _disappears_, then the above macro has a delay
before it pops up? Is this do-able? The other just isn't logical. It just
seems that the enable/disable macros prompt box has gotten hung.

Thanks much for your patience. D

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
"Ken Slovak - [MVP - Outlook]" wrote in message
...
Outlook VBA is not a scripting language, nor is any other variant of VBA
code. In VBA you can use the Win32 API Sleep method, just be very
careful to make sure it's not an infinite sleep since the thread still
has to process Windows messages.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 2000 ' sleep for 2000 ms = 2 seconds


Yes, that was impressed upon me very much by the very many messages in
response to this query in the archives. But there was no alternative
given. If need be, a looping mechanism or something that would have
accomplished the end result would have been fine. But did try this, both
with and without the "Private Declare" statement and I get an error
message so either I'm doing something wrong, or the syntax is incorrect.

Here's is the script:
***************************
Private Sub Application_Startup()
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Sleep 2000 ' sleep for 2000 ms = 2 seconds

strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes
Then
ExpandAllFolders
End If
End Sub
***************************

Whether or not the "Private Declare" line has been put in, either way the
vbe is brought up with "sleep" highlighted and the error:
"Sub of Function not defined."

Thanks.




  #6  
Old December 17th 07, 06:54 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default What is the equivalent in O2K vb to "Sleep()"?

As soon as you enable the macros to run the Sleep() method is called,
therefore preventing the Outlook thread from processing the message to close
that warning dialog. That's one of the reasons that people were warning
against using Sleep().

What you really need is a OnStartupComplete event, only available in COM
addins and not in the Outlook VBA project.

An alternative would be if you have a 3rd party timer control available to
you or one from Visual Studio 6. Then you can start the timer in Startup()
and set it for say 5 seconds and when the timer interrupt fires you can then
show your MsgBox. That would allow Outlook to process the message to close
that warning dialog about enabling macros while still having the timer run.

If you don't have a timer control available then you'd need to use a Win32
API timer, which is a lot more complicated to create and set up.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
"Ken Slovak - [MVP - Outlook]" wrote in message
...
The declaration for the Sleep() API function, as with any similar API
declarations, should be placed at module level and not inside another
method. Move it to above any code procedures in that module.


Okay, though I understand the words individually, didn't understand all
that above g. What I did get out of that was to put it at the very top
of the "module", so I put this line which seemed to be most logical pat to
put at the very top:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '
This line is so that you can use "Sleep" in any macro.


Then I changed the macro to this:
********************************************
Private Sub Application_Startup()
Sleep 2000 ' sleep for 2000 ms = 2 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub
********************************************
I even tried 5000 for 5 seconds. But it's still not behaving as it
should. The problem is that the box for this macro comes up on the heels
of the prompt to enable/disable macros. All the sleep does is delay that
enable/disable box from disappearing so that this box is _still_ being
called up on the heels of the other one's disappearance. Can we fine-tune
this to something more logical? What is needed is that _after_ the
disable/enable macros prompt _disappears_, then the above macro has a
delay before it pops up? Is this do-able? The other just isn't logical.
It just seems that the enable/disable macros prompt box has gotten hung.

Thanks much for your patience. D


  #7  
Old December 17th 07, 09:40 PM posted to microsoft.public.outlook.program_vba
StargateFanFromWork
external usenet poster
 
Posts: 39
Default What is the equivalent in O2K vb to "Sleep()"?

Thank you for the education. Much appreciated. Seems that Outlook makes
things difficult. Sleep works extremely well in other scripting programs
that I'm familiar with g. Ah well. Will just have to live without all
that and since I'm going to remove the sleep code and have the boxes pop up
one after the other. Not elegant, doesn't give one time to breath, and
might accidentally click the 2nd box too quickly, but I'll get just have to
get used to it. Better than that hanging box!

It's all just rather annoying. sigh

Thanks. D

"Ken Slovak - [MVP - Outlook]" wrote in message
...
As soon as you enable the macros to run the Sleep() method is called,
therefore preventing the Outlook thread from processing the message to
close that warning dialog. That's one of the reasons that people were
warning against using Sleep().

What you really need is a OnStartupComplete event, only available in COM
addins and not in the Outlook VBA project.

An alternative would be if you have a 3rd party timer control available to
you or one from Visual Studio 6. Then you can start the timer in Startup()
and set it for say 5 seconds and when the timer interrupt fires you can
then show your MsgBox. That would allow Outlook to process the message to
close that warning dialog about enabling macros while still having the
timer run.

If you don't have a timer control available then you'd need to use a Win32
API timer, which is a lot more complicated to create and set up.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
"Ken Slovak - [MVP - Outlook]" wrote in message
...
The declaration for the Sleep() API function, as with any similar API
declarations, should be placed at module level and not inside another
method. Move it to above any code procedures in that module.


Okay, though I understand the words individually, didn't understand all
that above g. What I did get out of that was to put it at the very top
of the "module", so I put this line which seemed to be most logical pat
to put at the very top:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '
This line is so that you can use "Sleep" in any macro.


Then I changed the macro to this:
********************************************
Private Sub Application_Startup()
Sleep 2000 ' sleep for 2000 ms = 2 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes
Then
ExpandAllFolders
End If
End Sub
********************************************
I even tried 5000 for 5 seconds. But it's still not behaving as it
should. The problem is that the box for this macro comes up on the heels
of the prompt to enable/disable macros. All the sleep does is delay that
enable/disable box from disappearing so that this box is _still_ being
called up on the heels of the other one's disappearance. Can we
fine-tune this to something more logical? What is needed is that _after_
the disable/enable macros prompt _disappears_, then the above macro has a
delay before it pops up? Is this do-able? The other just isn't logical.
It just seems that the enable/disable macros prompt box has gotten hung.

Thanks much for your patience. D




  #8  
Old December 17th 07, 09:54 PM posted to microsoft.public.outlook.program_vba
StargateFanFromWork
external usenet poster
 
Posts: 39
Default What is the equivalent in O2K vb to "Sleep()"?

Is there a possible workaround that somehow does what sleep _should_ do,
without keeping boxes from closing properly? Anything along this line:

Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds

This is actually an Excel code kindly given to me but I added it to the
beginning of the opening macro in a workbook and the enable macros box
closed and 3 seconds passed before the message box popped up so this _does_
work in Excel. The hour glass kept working during that 3 second wait but
that doesn't matter. The previous box closed immediately as it should and
didn't seem to hang, so that worked well.

Is there an Outlook equivalent?? I did try that code in the O2K vbe but get
this error:
"Run-time error '438':
Object doesn't support this property or method"

************************************************** **********
Private Sub Application_Startup()
Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub

************************************************** **********
Thanks. D

"StargateFanFromWork" wrote in message
...
Thank you for the education. Much appreciated. Seems that Outlook makes
things difficult. Sleep works extremely well in other scripting programs
that I'm familiar with g. Ah well. Will just have to live without all
that and since I'm going to remove the sleep code and have the boxes pop
up one after the other. Not elegant, doesn't give one time to breath, and
might accidentally click the 2nd box too quickly, but I'll get just have
to get used to it. Better than that hanging box!

It's all just rather annoying. sigh

Thanks. D

"Ken Slovak - [MVP - Outlook]" wrote in message
...
As soon as you enable the macros to run the Sleep() method is called,
therefore preventing the Outlook thread from processing the message to
close that warning dialog. That's one of the reasons that people were
warning against using Sleep().

What you really need is a OnStartupComplete event, only available in COM
addins and not in the Outlook VBA project.

An alternative would be if you have a 3rd party timer control available
to you or one from Visual Studio 6. Then you can start the timer in
Startup() and set it for say 5 seconds and when the timer interrupt fires
you can then show your MsgBox. That would allow Outlook to process the
message to close that warning dialog about enabling macros while still
having the timer run.

If you don't have a timer control available then you'd need to use a
Win32 API timer, which is a lot more complicated to create and set up.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
"Ken Slovak - [MVP - Outlook]" wrote in message
...
The declaration for the Sleep() API function, as with any similar API
declarations, should be placed at module level and not inside another
method. Move it to above any code procedures in that module.

Okay, though I understand the words individually, didn't understand all
that above g. What I did get out of that was to put it at the very
top of the "module", so I put this line which seemed to be most logical
pat to put at the very top:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' This line is so that you can use "Sleep" in any macro.


Then I changed the macro to this:
********************************************
Private Sub Application_Startup()
Sleep 2000 ' sleep for 2000 ms = 2 seconds
strMsg = "Do you want to run the macro to expand all the folders...
?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes
Then
ExpandAllFolders
End If
End Sub
********************************************
I even tried 5000 for 5 seconds. But it's still not behaving as it
should. The problem is that the box for this macro comes up on the heels
of the prompt to enable/disable macros. All the sleep does is delay
that enable/disable box from disappearing so that this box is _still_
being called up on the heels of the other one's disappearance. Can we
fine-tune this to something more logical? What is needed is that
_after_ the disable/enable macros prompt _disappears_, then the above
macro has a delay before it pops up? Is this do-able? The other just
isn't logical. It just seems that the enable/disable macros prompt box
has gotten hung.

Thanks much for your patience. D






  #9  
Old December 17th 07, 10:31 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default What is the equivalent in O2K vb to "Sleep()"?

There's no Outlook equivalent. You would have to use a timer control or a
Win32 API timer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
Is there a possible workaround that somehow does what sleep _should_ do,
without keeping boxes from closing properly? Anything along this line:

Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds

This is actually an Excel code kindly given to me but I added it to the
beginning of the opening macro in a workbook and the enable macros box
closed and 3 seconds passed before the message box popped up so this
_does_ work in Excel. The hour glass kept working during that 3 second
wait but that doesn't matter. The previous box closed immediately as it
should and didn't seem to hang, so that worked well.

Is there an Outlook equivalent?? I did try that code in the O2K vbe but
get this error:
"Run-time error '438':
Object doesn't support this property or method"

************************************************** **********
Private Sub Application_Startup()
Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes Then
ExpandAllFolders
End If
End Sub

************************************************** **********
Thanks. D


  #10  
Old December 17th 07, 10:35 PM posted to microsoft.public.outlook.program_vba
StargateFanFromWork
external usenet poster
 
Posts: 39
Default What is the equivalent in O2K vb to "Sleep()"?

Dang. Okay. Thanks much. Much appreciated!

D

"Ken Slovak - [MVP - Outlook]" wrote in message
...
There's no Outlook equivalent. You would have to use a timer control or a
Win32 API timer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
Is there a possible workaround that somehow does what sleep _should_ do,
without keeping boxes from closing properly? Anything along this line:

Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds

This is actually an Excel code kindly given to me but I added it to the
beginning of the opening macro in a workbook and the enable macros box
closed and 3 seconds passed before the message box popped up so this
_does_ work in Excel. The hour glass kept working during that 3 second
wait but that doesn't matter. The previous box closed immediately as it
should and didn't seem to hang, so that worked well.

Is there an Outlook equivalent?? I did try that code in the O2K vbe but
get this error:
"Run-time error '438':
Object doesn't support this property or method"

************************************************** **********
Private Sub Application_Startup()
Application.Wait Now + TimeSerial(0, 0, 3) ' 3 seconds
strMsg = "Do you want to run the macro to expand all the folders... ?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Expand all?") = vbYes
Then
ExpandAllFolders
End If
End Sub

************************************************** **********
Thanks. D




 




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

vB 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
What equivalent property name for the contact field "send plain text only" ? James Outlook - Using Contacts 3 August 28th 06 08:19 PM
What equivalent property name for the contact field "send plain text only" ? James Outlook - Using Forms 1 August 24th 06 12:29 PM
What equivalent property name for the contact field "send plain text only" ? James Outlook - Using Forms 0 August 24th 06 12:00 PM
Include "Telecommuting" or "Teleworking" as a "Show time as" statu Gordon Greene Outlook - Calandaring 0 July 31st 06 03:37 PM
equivalent of "http package" in Tcl Praveen Outlook and VBA 0 July 12th 06 03:10 PM


All times are GMT +1. The time now is 03:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.