How do I eliminate the "Enable Macro" selection?
#1: I'd keep that in place. In a few months you don't remember all the
details and might decide to rename the folder. Then the prompt will remind
you to update the code. Skipping that one wouldn't save you more than a
millisecond, if any.
#2: It's not necessary in your code, but again the saved time is not worth
worrying about.
#3: VB(A) automatically sets the variables to Nothing as soon as you leave
the function.
So, actually you can delete all the mentioned lines of code. But time could
be saved only within the loop. And there's nothing you can do except maybe
to use a variable set to the Selection object:
Dim Sel as Outlook.Selection
Set Sel=Application.ActiveExplorer.Selection
For Each objItem in Sel
....
Next
--
Best regards
Michael Bauer - MVP Outlook
: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en
Am Fri, 18 Sep 2009 19:19:01 -0700 schrieb Keith:
Thanks you so much Michael and JP
I made the suggested change (At least I think I did – it still works
anyway!)
Your input lead me to ask some questions which I have added as comments.
I
really really appreciate your help.
So here is the new code:
Sub MoveToTrash()
On Error Resume Next
Dim objFolder As MAPIFolder
Dim objNS As NameSpace
Dim objItem As MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("KJB").Folders("Trash")
' is this redundant since the folder name is hard coded and doesnt
change??
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If
' Is this test needed since it appears the FOR loop below takes care of
this test
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
objItem.UnRead = False
objItem.Move objFolder
Next
' Do these items need to be set to nothing. Wont they be removed from
the
heap or stack when the sub() ends?
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
End Sub
|