random signature vba assistance

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: bschanba (bschanba_at_esu10.org)
Date: 11/30/04


Date: 30 Nov 2004 10:24:15 -0800

I want to have a random quote included in my signature file, and
included the code below in Outlook 2003 ThisOutlookSession class. It
works, but it is still causing the "A program is trying to access
e-mail addresses..." Huge thanks to Sue Mosher for all the info
posted. But I need clarification on this snippet:

However, Outlook 2003 does not show security prompts on three specific
types
of applications:
   -- VBScript code in published, non-oneoff Outlook forms
   -- Outlook VBA code that uses the intrinsic Application object
   -- Outlook COM add-ins properly constructed to derive all objects
from the Application object passed by the OnConnection event

The vba code uses the intrinsic Application object, so it shouldn't be
showing the security prompt for that reason. Is this not correct, or
is there another reason this code gives the security prompt? Or if
anyone has another way of doing this same thing, I'd appreciate it.
Thanks in advance!

Option Explicit
Dim intQuotes As Integer
Dim strTop, strBottom, aryQuotes() As String
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objEmail As Outlook.MailItem

Private Sub Application_Startup()
    Set objInspectors = Application.Inspectors
    
    'top (consistant) part of signature
    strTop = "My name and company here" & vbCrLf
    'number of quotes in array below
    intQuotes = 12
    'random quotes in signature in zero-based array
    ReDim aryQuotes(intQuotes) As String
    aryQuotes(0) = "quote here"
    '...
    aryQuotes(11) = "another quote here"
    'top (consistant) part of signature
    strBottom = "bottom of signature here" & vbCrLf

End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    If Inspector.CurrentItem.Class <> olMail Then Exit Sub
    Set objEmail = Inspector.CurrentItem
End Sub

Private Sub objEmail_Open(Cancel As Boolean)
    If objEmail.LastModificationTime <> "1/1/4501" Then Exit Sub
    Dim intRandom As Integer, strSignature As String
    intRandom = Int(intQuotes * Rnd())
    strSignature = strTop & aryQuotes(intRandom) & strBottom
    objEmail.Body = strSignature & objEmail.Body
End Sub

Private Sub Application_Quit()
    Set objInspectors = Nothing
End Sub



Relevant Pages

  • Re: Problem using NewMailEx
    ... it is a way of periodically checking the shared mailbox. ... Author of Microsoft Outlook 2007 Programming: ... Private Sub Application_NewMailEx ... Dim DeletedFolder As Outlook.MAPIFolder ...
    (microsoft.public.outlook.program_vba)
  • Re: Reading Pane in vba
    ... Private Sub objDocumentItem_BeforeAttachmentPreview(ByVal Attachment ... Dim olParent As Outlook.DocumentItem ... When i save it Outlook crashes and wants to restart itself so i have ...
    (microsoft.public.outlook.program_vba)
  • Re: Outlook COM Addin with Visual Basic
    ... Outlook COM addin implementation (such as On_Disconnection not firing ... > Dim WithEvents oApp As Outlook.Application ... > Private Sub IDTExtensibility2_OnBeginShutdown(_ ... > Set myItem = oApp.CreateItem ...
    (microsoft.public.outlook.program_vba)
  • Re: Drag and Drop from Outlook to Vb.net RichTextBox
    ... After some researching I got a working sample using outlook automation, ... Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ... Dim myMem As New MemoryStream ... bigger and better idiot-proof programs, and the Universe trying to produce ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Reply/Reply All
    ... Dim selectedItems As New System.Collections.ArrayList ... Public mailItem As Outlook.MailItem = Nothing ... Private Sub ThisApplication_Startup(ByVal sender As Object, ... OutlookSpy - Outlook, CDO ...
    (microsoft.public.outlook.program_vba)