msoutlook.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Outlook VBA advice

 
Post new topic   Reply to topic    msoutlook.org Forum Index -> MS Office Outlook
Author Message
LanceVictor



Joined: 23 Jan 2008
Posts: 2

PostPosted: Wed Jan 23, 2008 7:13 pm    Post subject: Outlook VBA advice Reply with quote

I'm new to VBA and was wondering if anyone could give me any pointers
on how I could speed up the following script for Outlook. It seems to
run extremely slowly, expecially if there are a number of mail items
selected....
* * * * *
Option Explicit

Sub TrashMail()

Dim ImapRoot As MAPIFolder: Set ImapRoot =
Application.GetNamespace("MAPI").Folders("imap.telus.net")
Dim TrashFolder As MAPIFolder: Set TrashFolder =
ImapRoot.Folders("Deleted Items")
Dim myBar As CommandBar: Set myBar =
Application.ActiveExplorer.CommandBars("Menu Bar")
Dim myButtonPopup As CommandBarPopup: Set myButtonPopup =
myBar.Controls("Edit")
Dim myButton As CommandBarButton: Dim strRes As String:
Dim flgImap As Boolean: Dim flgDeleted
As Boolean

On Error Resume Next

strRes = ActiveExplorer.Selection.Count: If strRes = "" Or strRes =
"0" Then Exit Sub

strRes = ActiveExplorer.CurrentFolder.FolderPath
If InStr(1, strRes, "Deleted", 1) > 0 Then: flgDeleted = True: Else:
flgDeleted = False:
If InStr(1, strRes, "imap", 1) > 0 Then: flgImap = True: Else: flgImap
= False:

If flgImap = False Then
Set myButton = myButtonPopup.Controls("Delete"):
myButton.Execute
Else
If flgDeleted = True Then
Set myButton = myButtonPopup.Controls("Delete"):
myButton.Execute
Else
Dim Item As MailItem
For Each Item In ActiveExplorer.Selection
Item.Move TrashFolder
Next Item
End If
Set myButton = myButtonPopup.Controls("Purge Deleted
Messages"): myButton.Execute
End If

End Sub

Archived from group: microsoft>public>office>developer>outlook>vba
Back to top
View user's profile Send private message
JP



Joined: 21 Nov 2007
Posts: 33

PostPosted: Thu Jan 24, 2008 12:07 am    Post subject: Re: Outlook VBA advice Reply with quote

Could you explain what you are trying to do and maybe someone can
suggest an alternate way of coding it.


Thx,
JP

On Jan 23, 5:13 pm, LanceVictor wrote:
> I'm new to VBA and was wondering if anyone could give me any pointers
> on how I could speed up the following script for Outlook.  It seems to
> run extremely slowly, expecially if there are a number of mail items
> selected....
> * * * * *
> Option Explicit
>
> Sub TrashMail()
>
> Dim ImapRoot As MAPIFolder:                        Set ImapRoot =
> Application.GetNamespace("MAPI").Folders("imap.telus.net")
> Dim TrashFolder As MAPIFolder:                     Set TrashFolder =
> ImapRoot.Folders("Deleted Items")
> Dim myBar As CommandBar:                          Set myBar =
> Application.ActiveExplorer.CommandBars("Menu Bar")
> Dim myButtonPopup As CommandBarPopup:   Set myButtonPopup =
> myBar.Controls("Edit")
> Dim myButton As CommandBarButton:            Dim strRes As String:
> Dim flgImap As Boolean:                                 Dim flgDeleted
> As Boolean
>
> On Error Resume Next
>
> strRes = ActiveExplorer.Selection.Count:  If strRes = "" Or strRes =
> "0" Then Exit Sub
>
> strRes = ActiveExplorer.CurrentFolder.FolderPath
> If InStr(1, strRes, "Deleted", 1) > 0 Then: flgDeleted = True: Else:
> flgDeleted = False:
> If InStr(1, strRes, "imap", 1) > 0 Then: flgImap = True: Else: flgImap
> = False:
>
> If flgImap = False Then
>     Set myButton = myButtonPopup.Controls("Delete"):
> myButton.Execute
> Else
>     If flgDeleted = True Then
>         Set myButton = myButtonPopup.Controls("Delete"):
> myButton.Execute
>     Else
>         Dim Item As MailItem
>         For Each Item In ActiveExplorer.Selection
>             Item.Move TrashFolder
>         Next Item
>     End If
>     Set myButton = myButtonPopup.Controls("Purge Deleted
> Messages"):    myButton.Execute
> End If
>
> End Sub
Back to top
View user's profile Send private message
LanceVictor



Joined: 23 Jan 2008
Posts: 2

PostPosted: Fri Jan 25, 2008 2:17 am    Post subject: Re: Outlook VBA advice Reply with quote

On Jan 23, 7:07 pm, JP wrote:
> Could you explain what you are trying to do and maybe someone can
> suggest an alternate way of coding it.

I'm trying to make my IMAP account move messages to a 'deleted items'
folder when I push the "Delete" button (which is attached to the
script), but it seems to work so slowly....

Thanks,
Lance
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Fri Jan 25, 2008 2:27 pm    Post subject: Re: Outlook VBA advice Reply with quote

It will work slowly because each access must hit the server. Either download
the items to a PST file or expect rather slow response to your code.

--
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


"LanceVictor" wrote in message @q21g2000hsa.googlegroups.com...
On Jan 23, 7:07 pm, JP wrote:
> Could you explain what you are trying to do and maybe someone can
> suggest an alternate way of coding it.

I'm trying to make my IMAP account move messages to a 'deleted items'
folder when I push the "Delete" button (which is attached to the
script), but it seems to work so slowly....

Thanks,
Lance

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Outlook ignoring html font tag - VBA - Access 2007 & Outlook Seeing another pair of eyes to tell me where I'm missing some key element. My code below works fine to create a message however the font tag is ignored and everything comes out as Times New Roman 12pt. Any assist would be greatly appreciated. strMailMsg

i made a plugin of outlook that crashes in outlook 2007 on v Hi I am facing a Problem that i have made a plugin in Visual Studio 2000 using VC6.0 that is running fine in outlook 2003 and on all the operating but when i run that plugin on Outlook2007 installed on Microsoft Vista( licensed )

Problems with shutdown in Outlook 2007 when using Outlook Ob Hi, I've written an application that logs into Outlook, accesses some of the user's data, and logs out. A problem occurs if I run the application twice in a row, without waiting long after the application exits the first time. The first time the program

Add Outlook Express feature to Outlook - autocomplete I've got a user who doesn't want to switch from Outlook Express to Outlook because Outlook doesn't have the autocomplete for emails addresses. I know you can type in a few characters and then hit ctrl-k, but it would be much easier on me if I could make

outlook &outlook express sounds I use both soft for differents reasons. In outlook I have the ability to use vb code to process hundreds messages per day In outlook express, my personnals and professionals account sit. Both use the same sound for incoming messages. Does somebody know ho
Post new topic   Reply to topic    msoutlook.org Forum Index -> MS Office Outlook All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group