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

How do I eliminate the "Enable Macro" selection?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 19th 09, 03:19 AM posted to microsoft.public.outlook.program_vba
keith
external usenet poster
 
Posts: 71
Default How do I eliminate the "Enable Macro" selection?

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

  #2  
Old September 19th 09, 12:56 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default 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

  #3  
Old September 20th 09, 06:48 PM posted to microsoft.public.outlook.program_vba
keith
external usenet poster
 
Posts: 71
Default How do I eliminate the "Enable Macro" selection?

I made all the changes Michel, thanks a lot.

Actually I think the slow speed is in part because of the way I invoke the
macro.

I select on item then invoke the macro by pressing my macro button, then I
repeat for the next item, etc.

A better method would be to select multiple items first and then invoke the
macro once to move the multiple selected items at once.

For completeness, here is my final code:

Sub MoveToTrash()
On Error Resume Next

Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItem As MailItem
Dim Sel As Outlook.Selection

' "Trash" folder in user namespace
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("KJB").Folders("Trash")

' Warn if "Trash" folder doesnt exist
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

' User selected emails to move to trash
Set Sel = Application.ActiveExplorer.Selection

' For each mail item in user selection, move it to "Trash" folder
For Each objItem In Sel
objItem.UnRead = False
objItem.Move objFolder
Next
End Sub

  #4  
Old September 20th 09, 07:10 PM posted to microsoft.public.outlook.program_vba
keith
external usenet poster
 
Posts: 71
Default How do I eliminate the "Enable Macro" selection?

Can this code be compiled to make it run faster or is the VBA code interpreted?

I guess the speed things is just my observation. If I hit the delete key,
its very fast, if I hit my macro button it might take a second to run and
complete the move so it seems slow.
  #5  
Old September 21st 09, 08:59 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default How do I eliminate the "Enable Macro" selection?



I think moving an IMAP message is what takes most of the time. There's
nothing you can do to speed it up.

--
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 Sun, 20 Sep 2009 11:10:01 -0700 schrieb Keith:

Can this code be compiled to make it run faster or is the VBA code

interpreted?

I guess the speed things is just my observation. If I hit the delete key,
its very fast, if I hit my macro button it might take a second to run and
complete the move so it seems slow.

  #6  
Old September 21st 09, 08:10 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default How do I eliminate the "Enable Macro" selection?

Don't worry, it happens to all of us The code I've written to move
or delete multiple emails always runs slower than the Del key.

--JP

On Sep 20, 2:10*pm, Keith wrote:
Can this code be compiled to make it run faster or is the VBA code interpreted?

I guess the speed things is just my observation. *If I hit the delete key,
its very fast, if I hit my macro button it might take a second to run and
complete the move so it seems slow.


  #7  
Old September 21st 09, 08:33 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default How do I eliminate the "Enable Macro" selection?

VBA code will always be slower than Extended MAPI code of course.

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


"JP" wrote in message
...
Don't worry, it happens to all of us The code I've written to move
or delete multiple emails always runs slower than the Del key.

--JP

  #8  
Old September 21st 09, 08:44 PM posted to microsoft.public.outlook.program_vba
keith
external usenet poster
 
Posts: 71
Default How do I eliminate the "Enable Macro" selection?

Well that's reassuring JP - I was about to talk to my therapist about why
Outlook is making me feel a victim. Guess I can cancel that appointment now


 




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
Eliminate need for "Enable Macro" selection cte67 Outlook and VBA 7 August 21st 09 06:30 PM
eliminate error message "Borlane Database Engine not installed" Outlook 2007 needs help - Outlook - Installation 2 June 5th 08 05:47 PM
How do I edit "show time as" drop down selection? DGarton Outlook - Calandaring 1 November 29th 07 10:56 PM
find/eliminate "active content" in a customized outlook form TomS Outlook - Using Forms 1 August 3rd 07 03:54 PM
how to delete email address from "to" button selection Buckskin Outlook - Using Contacts 2 June 11th 07 11:56 PM


All times are GMT +1. The time now is 12:46 AM.


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.