Re: Outlook 2003 Macro Causes VBA to be Disabled

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ken Slovak - [MVP - Outlook] (kenslovak_at_mvps.org)
Date: 07/07/04


Date: Wed, 7 Jul 2004 17:06:32 -0400

I can see problems from this line:
    Set objApp = New Application

Why do that at all? Just use Application. That's an intrinsic object in
Outlook VBA and Outlook 2003 VBA code is very sensitive to things like that.
New Application will produce untrusted VBA code and inherently any Outlook
VBA code that uses the built-in Application object and derives all other
Outlook objects from that is considered as trusted.

I'd also fully qualify all my declarations, not As NameSpace but As
Outlook.NameSpace and so on.

-- 
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Clif Haugen" <cliffo41@hotmail.com> wrote in message
news:fcdc0f23.0407071210.505c1cfa@posting.google.com...
> The following code works fine in Outlook 2000 and 2002.  However, in
> 2003 the code runs fine but the next time Outlook is started it will
> disable the VBA module.
>
> I've tried to replace the .OTM file for the session and that hasn't
> fixed the problem.  I've also replaced all of my Outlook.Application
> syntax with just Application.  That hasn't worked.  I've also looked
> for any missing Set statements, but can't locate any.
>
> The offending code is below.  I can't claim to have created it - it
> was posted in this newsgroup some time ago.  I've made a few
> modifications and find it very helpful for dealing with Junk Senders.
>
> I would _really_ appreciate any thoughts!!
>
> Clifford
>
> Private Const JUNK_SENDERS_FILE As String = _
>     "C:\Documents and Settings\jim smartt\Application
> Data\Microsoft\Outlook\Junk Senders.txt"
>
>
> Public Sub MultipleJunkEMailSenders()
>     Dim objNS As NameSpace
>     Dim objApp As Application
>     Dim objExp As Explorer
>     Dim objMessage As Object
>     Dim objMailItem As MailItem
>     Dim objReply As MailItem
>     Dim objItems As Items
>     Dim objExplorer As Explorer
>     Dim intItem As Integer
>     Dim objFSO As Scripting.FileSystemObject
>     Dim objTextStream As Scripting.TextStream
>     Dim CPH As String
>
>     Set objApp = New Application
>     Set objNS = objApp.GetNamespace("MAPI")
>     Set objExp = objApp.ActiveExplorer
>     Set objFSO = New Scripting.FileSystemObject
>
>         If objFSO.FileExists(FileSpec:=JUNK_SENDERS_FILE) = False Then
>             Set objTextStream = objFSO.CreateTextFile _
>                 (FileName:=JUNK_SENDERS_FILE)
>         Else
>             Set objTextStream = objFSO.OpenTextFile _
>                 (FileName:=JUNK_SENDERS_FILE, IOMode:=ForAppending)
>         End If
>
>         Set objExplorer = Application.ActiveExplorer
>
>         For Each objMessage In objExplorer.Selection
>
>             Set objMailItem = objMessage
>             Set objReply = objMailItem.Reply
>             CPH = objReply.Recipients.Item(1).Address
>             objReply.Close olDiscard
>             objTextStream.WriteLine Text:=CPH
>             objMailItem.UnRead = True
>             objMailItem.Delete
>
>         Next objMessage
>
> End Sub


Relevant Pages

  • Re: Memory does not decrease
    ... I need to programmatically export items (Outlook Custom Forms, ... I need OL2003 VBA code because I must avoid security warnings when I use ... Dim olApp As Outlook.Application ... Set olItem = colItems.GetFirst ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Integrating with outlook: VBA code
    ... editing the VBA code to the Project Developer newsgroup. ... Project MVP ... Dim appOL As Outlook.Application ... 'note that you can capture other Project fields into Outlook fields ...
    (microsoft.public.project)
  • Question abt Outlook 2003 VBA application by Sue Mosher*10152008
    ... ' built-in ThisOutlookSession session module in Outlook VBA ... Dim strAddress As String ... Set objContact = colContacts.Find ...
    (microsoft.public.outlook.program_vba)
  • Re: Permissions on other users calendars / recurring appointments
    ... In VBA, yes I do. ... "Dmitry Streblechenko" wrote: ... OutlookSpy - Outlook, CDO ... Dim oFdr As Outlook.MAPIFolder ...
    (microsoft.public.outlook.program_vba)
  • Re: Getting Started - Reading attachment
    ... The main limitation for VBA code is it's not designed for deployment to other users, and it can't handle Outlook 2007 or 2010 Ribbon or FormRegion callbacks. ... Dim colItems As Outlook.Items ...
    (microsoft.public.outlook.program_vba)