PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Way to add prompt to this macro?

Reply

Way to add prompt to this macro?

 
Thread Tools Rate Thread
Old 16-12-2007, 04:54 PM   #1
StargateFan
Guest
 
Posts: n/a
Default Way to add prompt to this macro?


Hi! I was given a fantastic script on this board some time back which
I use all the time. It sorts the folders in the main Personal
Folders. This is the script here:

****************************************************************
Private Sub Application_Startup()
ExpandAllFolders
End Sub

Private Sub ExpandAllFolders()
On Error Resume Next
Dim Ns As Outlook.NameSpace
Dim Folders As Outlook.Folders
Dim CurrF As Outlook.MAPIFolder
Dim F As Outlook.MAPIFolder
Dim ExpandDefaultStoreOnly As Boolean

ExpandDefaultStoreOnly = True

Set Ns = Application.GetNamespace("Mapi")
Set CurrF = Application.ActiveExplorer.CurrentFolder

If ExpandDefaultStoreOnly = True Then
Set F = Ns.GetDefaultFolder(olFolderInbox)
Set F = F.Parent
Set Folders = F.Folders
LoopFolders Folders, True

Else
LoopFolders Ns.Folders, True
End If

DoEvents
Set Application.ActiveExplorer.CurrentFolder = CurrF
End Sub
Private Sub LoopFolders(Folders As Outlook.Folders, _
ByVal bRecursive As Boolean _
)
Dim F As Outlook.MAPIFolder

For Each F In Folders
Set Application.ActiveExplorer.CurrentFolder = F
DoEvents

If bRecursive Then
If F.Folders.Count Then
LoopFolders F.Folders, bRecursive
End If
End If
Next
End Sub
****************************************************************

The thing is that the process takes a bit of time, which is absolutely
no problem. But a lot of times, the folders don't need to be expanded
each and every time O2K is launched and/or I need to get in
immediately.

How can we add a prompt to run this macro rather than having it run
automatically when all macros are enabled, pls?

Thank you! D
  Reply With Quote
Old 16-12-2007, 07:29 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Way to add prompt to this macro?

Use a MsgBox statement:

Private Sub Application_Startup()
If MsgBox("Do you want to expand?", vbYesNo + vbQuestion, "Expand all?") Then
ExpandAllFolders
End If
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"StargateFan" <IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote in message news:hieam3de2mc7mu5gefgm8jugg8jemo33ph@4ax.com...
> Hi! I was given a fantastic script on this board some time back which
> I use all the time. It sorts the folders in the main Personal
> Folders. This is the script here:
>
> ****************************************************************
> Private Sub Application_Startup()
> ExpandAllFolders
> End Sub
>
> Private Sub ExpandAllFolders()
> On Error Resume Next
> Dim Ns As Outlook.NameSpace
> Dim Folders As Outlook.Folders
> Dim CurrF As Outlook.MAPIFolder
> Dim F As Outlook.MAPIFolder
> Dim ExpandDefaultStoreOnly As Boolean
>
> ExpandDefaultStoreOnly = True
>
> Set Ns = Application.GetNamespace("Mapi")
> Set CurrF = Application.ActiveExplorer.CurrentFolder
>
> If ExpandDefaultStoreOnly = True Then
> Set F = Ns.GetDefaultFolder(olFolderInbox)
> Set F = F.Parent
> Set Folders = F.Folders
> LoopFolders Folders, True
>
> Else
> LoopFolders Ns.Folders, True
> End If
>
> DoEvents
> Set Application.ActiveExplorer.CurrentFolder = CurrF
> End Sub
> Private Sub LoopFolders(Folders As Outlook.Folders, _
> ByVal bRecursive As Boolean _
> )
> Dim F As Outlook.MAPIFolder
>
> For Each F In Folders
> Set Application.ActiveExplorer.CurrentFolder = F
> DoEvents
>
> If bRecursive Then
> If F.Folders.Count Then
> LoopFolders F.Folders, bRecursive
> End If
> End If
> Next
> End Sub
> ****************************************************************
>
> The thing is that the process takes a bit of time, which is absolutely
> no problem. But a lot of times, the folders don't need to be expanded
> each and every time O2K is launched and/or I need to get in
> immediately.
>
> How can we add a prompt to run this macro rather than having it run
> automatically when all macros are enabled, pls?
>
> Thank you! D

  Reply With Quote
Old 16-12-2007, 08:44 PM   #3
StargateFan
Guest
 
Posts: n/a
Default Re: Way to add prompt to this macro?

On Sun, 16 Dec 2007 14:29:33 -0500, "Sue Mosher [MVP-Outlook]"
<suemvp@outlookcode.com> wrote:

>Use a MsgBox statement:
>
>Private Sub Application_Startup()
> If MsgBox("Do you want to expand?", vbYesNo + vbQuestion, "Expand all?") Then
> ExpandAllFolders
> End If
>End Sub



WOW!! That is so kewl!! I just changed the text a bit to this:
"Private Sub Application_Startup()
If MsgBox("Do you want to run the macro to expand all the
folders... ?", vbYesNo + vbQuestion, "Expand all?") Then
ExpandAllFolders
End If
End Sub"

and then it ran the macro at triple speed! Pretty kewl.

Is there a "sleep" function in vb? I'd like to add a second or 2 or
sleep before the message box comes up. This box pops up a bit too
quickly after one presses okay to enable macros.

Thanks for this! D

>--
>Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
>"StargateFan" <IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote in message news:hieam3de2mc7mu5gefgm8jugg8jemo33ph@4ax.com...
>> Hi! I was given a fantastic script on this board some time back which
>> I use all the time. It sorts the folders in the main Personal
>> Folders. This is the script here:
>>
>> ****************************************************************
>> Private Sub Application_Startup()
>> ExpandAllFolders
>> End Sub
>>
>> Private Sub ExpandAllFolders()
>> On Error Resume Next
>> Dim Ns As Outlook.NameSpace
>> Dim Folders As Outlook.Folders
>> Dim CurrF As Outlook.MAPIFolder
>> Dim F As Outlook.MAPIFolder
>> Dim ExpandDefaultStoreOnly As Boolean
>>
>> ExpandDefaultStoreOnly = True
>>
>> Set Ns = Application.GetNamespace("Mapi")
>> Set CurrF = Application.ActiveExplorer.CurrentFolder
>>
>> If ExpandDefaultStoreOnly = True Then
>> Set F = Ns.GetDefaultFolder(olFolderInbox)
>> Set F = F.Parent
>> Set Folders = F.Folders
>> LoopFolders Folders, True
>>
>> Else
>> LoopFolders Ns.Folders, True
>> End If
>>
>> DoEvents
>> Set Application.ActiveExplorer.CurrentFolder = CurrF
>> End Sub
>> Private Sub LoopFolders(Folders As Outlook.Folders, _
>> ByVal bRecursive As Boolean _
>> )
>> Dim F As Outlook.MAPIFolder
>>
>> For Each F In Folders
>> Set Application.ActiveExplorer.CurrentFolder = F
>> DoEvents
>>
>> If bRecursive Then
>> If F.Folders.Count Then
>> LoopFolders F.Folders, bRecursive
>> End If
>> End If
>> Next
>> End Sub
>> ****************************************************************
>>
>> The thing is that the process takes a bit of time, which is absolutely
>> no problem. But a lot of times, the folders don't need to be expanded
>> each and every time O2K is launched and/or I need to get in
>> immediately.
>>
>> How can we add a prompt to run this macro rather than having it run
>> automatically when all macros are enabled, pls?
>>
>> Thank you! D


  Reply With Quote
Old 16-12-2007, 09:05 PM   #4
StargateFan
Guest
 
Posts: n/a
Default Re: Way to add prompt to this macro?

On Sun, 16 Dec 2007 15:44:49 -0500, StargateFan
<IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote:

>On Sun, 16 Dec 2007 14:29:33 -0500, "Sue Mosher [MVP-Outlook]"
><suemvp@outlookcode.com> wrote:
>
>>Use a MsgBox statement:
>>
>>Private Sub Application_Startup()
>> If MsgBox("Do you want to expand?", vbYesNo + vbQuestion, "Expand all?") Then
>> ExpandAllFolders
>> End If
>>End Sub

>
>
>WOW!! That is so kewl!! I just changed the text a bit to this:
> "Private Sub Application_Startup()
> If MsgBox("Do you want to run the macro to expand all the
>folders... ?", vbYesNo + vbQuestion, "Expand all?") Then
> ExpandAllFolders
> End If
>End Sub"
>
>and then it ran the macro at triple speed! Pretty kewl.
>
>Is there a "sleep" function in vb? I'd like to add a second or 2 or
>sleep before the message box comes up. This box pops up a bit too
>quickly after one presses okay to enable macros.
>
>Thanks for this! D


[snip]

Oops, didn't check it out thoroughly. The macro still runs even when
we press NO!

(

How come? <g>

Thanks. D

  Reply With Quote
Old 16-12-2007, 10:55 PM   #5
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Way to add prompt to this macro?

Because I stupidly forgot the text for the MsgBox function's return value:

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

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"StargateFan" <IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote in message news:3n4bm3hm1vj9otk4q4pkh97948g7nrh37p@4ax.com...
> On Sun, 16 Dec 2007 15:44:49 -0500, StargateFan
> <IDon'tAcceptSpam@IDon'tAcceptSpam.com> wrote:
>
>>On Sun, 16 Dec 2007 14:29:33 -0500, "Sue Mosher [MVP-Outlook]"
>><suemvp@outlookcode.com> wrote:
>>
>>>Use a MsgBox statement:
>>>
>>>Private Sub Application_Startup()
>>> If MsgBox("Do you want to expand?", vbYesNo + vbQuestion, "Expand all?") Then
>>> ExpandAllFolders
>>> End If
>>>End Sub

>>
>>
>>WOW!! That is so kewl!! I just changed the text a bit to this:
>> "Private Sub Application_Startup()
>> If MsgBox("Do you want to run the macro to expand all the
>>folders... ?", vbYesNo + vbQuestion, "Expand all?") Then
>> ExpandAllFolders
>> End If
>>End Sub"
>>
>>and then it ran the macro at triple speed! Pretty kewl.
>>
>>Is there a "sleep" function in vb? I'd like to add a second or 2 or
>>sleep before the message box comes up. This box pops up a bit too
>>quickly after one presses okay to enable macros.
>>
>>Thanks for this! D

>
> [snip]
>
> Oops, didn't check it out thoroughly. The macro still runs even when
> we press NO!
>
> (
>
> How come? <g>
>
> Thanks. D
>

  Reply With Quote
Old 17-12-2007, 12:53 PM   #6
StargateFan
Guest
 
Posts: n/a
Default Re: Way to add prompt to this macro?

On Sun, 16 Dec 2007 17:55:15 -0500, "Sue Mosher [MVP-Outlook]"
<suemvp@outlookcode.com> wrote:

>Because I stupidly forgot the text for the MsgBox function's return value:
>
> 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


<lol> Thank you! Works just perfectly now. Next time a colleague
comes around just as I've opened Outlook, I can press "no" before he
asks me something that requires an email response and we don't need to
wait for the macro to go through <g>. (That literally happened to me
a couple of weeks ago; freaks people out, this macro does <lol>. I
should have just chosen disable then re-opened O2K after, but didn't
think of that on the spur of the moment ... <g>).

Also, what's neat is that I can see the folders and they remain
expanded a few times Outlook opens, so it needs the macro run only
every few launches. Pretty neat O2K behaviour not to need to do it
each time.

  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off