home | get Sue’s code | forums | share code | registration

More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

share code 09-Feb-2010 11:12

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

Code level: intermediate    Code area: Basic Outlook Printer Friendly Version
Title: Attachment checker 1.0
Description: This is my final attempt (for now) at making an attachment checker. This event procedure will check an outgoing message, first for a blank Subject, then the Subject and Body to see if an attachment should be attached (based on keyword/phrases). Most of the functionality is explained in the procedure notes and code comments. It's working for me, hopefully it will work for you. The hard part was working with html message bodies.
Date: 23-Aug-2004  13:41
Code level: intermediate
Code area: Basic Outlook
Posted by: Jeremy Gollehon
Body:
All 31comments
Page [ 1 2 3 4 Next >>  
  26-Aug-2004  12:15   
Love your code. I'm adapting it to run as a function called from my own ItemSend event. One issue comes up, which I've run into before. The line:

Dim oSMail As Redemption.SafeMailItem

gives me an error of "User-defined type not defined". I have Redemption installed and use it in my own code. How do I properly define this type?

TIA.

- Jeff
  26-Aug-2004  12:31   
Got it. I needed to import the type library (or the reference, or whatever, in VBA-speak).
  26-Aug-2004  13:13   
Hi Jeff,
Glad you like the code and that you got it working.

One thing.
I did notice that I could take out one sort of redundant line from the code.
The line in the search loop:
If InStr(sTextToSearch, vKeyWords(i)) > 0 Then
isn't really needed. It doesn't save any time as the ExactMatch function is a one liner anyway.

-Jeremy
  30-Aug-2004  13:22   
I tried an earlier version of the code and updated to this one. However, I do not have Redemption and I don't know what it is. Can you please advise! Thanks
  30-Aug-2004  14:55   
Redemption is a third-party library that wraps Extended MAPI to avoid security prompts and provide functionality that the Outlook object model doesn't contain -- http://www.dimastr.com/redemption/
  31-Aug-2004  11:31   
Simple instructions on how to install Redemption.

1) At http://www.dimastr.com/redemption, click Download.
2) On the download page click "Download Developer version"
3) Save to somewhere on your computer, unzip and run the .exe file. The installer puts a dll in your Program Files directory and registers it with Windows.
4) In the Outlook VBE go to Tools > References and set an active reference to SafeOutlook Library.
5) You may have to restart Outlook.
  06-Oct-2004  07:28   
I've been trying to bash together two bits of code, the one above and another that forwards the selected message. What I'm trying to achieve is to search the selected message for the name of a sports centre and use this to create an email address to forward the original message to (in this case by concatenating "LF, " and the sports centre name which is recognised as a valid address in outlook in my office).

Since I'll only ever be forwarding messages that contain the centre name after the text "::::: C L O S E S T C L U B :::::" since they're sent via a web form I've tried to adapt Jeremy's code to specify the text to be searched should always be to the right of this text.

The first line I'm getting stuck at when trying to run the code (below) is:

sTextToSearch = Item.Body

No doubt something to do with the way I've combined the two routines. Anyone have any ideas or know of another already created code that will do the job I'm after?

Cheers

Bobwhosmiles



Sub FwdWebinfo()
    Dim objApp As Application
    Dim objSelection As Selection
    Dim blnDoIt As Boolean
    Dim i As Integer
    Dim strMsg As String

    Set objApp = CreateObject("Outlook.Application")
    Set objSelection = objApp.ActiveExplorer.Selection

    blnDoIt = False
        ' If no messages selected, tell the user
    If objSelection.Count = 0 Then
        Call Email_not_selected
    ElseIf objSelection.Count = 1 Then
        ' 1 message selected, just do it
        blnDoIt = True
    Else
        ' more than 1 messge is selected so warn user
        strMsg = "Only select one message at a time to forward"
        i = MsgBox( _
            Prompt:=strMsg, _
            Buttons:=vbOKOnly + vbDefaultButton0, _
            Title:="Multiple Selection")
        Exit Sub
    End If
    
    If blnDoIt = True Then
        Call Fwd_selected_items(objSelection)
        Beep ' alert the user that we're done
    End If
    Set objSelection = Nothing
    Set objApp = Nothing
End Sub

' Tell user that no email message was selected
'
Sub Email_not_selected()

    Dim i As Integer

    i = MsgBox(Prompt:="You need to select a message or messages to forward", _
            Buttons:=vbDefaultButton2, _
            Title:="Unrecognized Selection")
     
End Sub


' For selected message, send to the appropriate email address
'
Sub Fwd_selected_item(objSel As Selection)

    Dim objItem As Object
    Dim intOKToExceedMax As Integer
    Dim iStartOfQuote As Long
    Dim sTextToSearch As String
    Dim sKeyWords As String
    Dim vKeyWords() As String
    Dim iCentreToReceive As String
    Dim i As Long

    sKeyWords = "Bellahouston;Castlemilk;Donald_;Drumchapel;Easterhouse;Haghill;Gorbals;Holyrood;Kelvinhall;Maryhill;Nethercraigs;Northwoodside;Pollock;Scotstoun;Tollcross;Whitehill;Yoker"

    sTextToSearch = Item.Body
    iStartOfQuote = InStr(Item.Body, "::::: C L O S E S T C L U B :::::") - 1
    If iStartOfQuote > 0 Then sTextToSearch = Right(sTextToSearch, iStartOfQuote)

    vKeyWords = Split(sKeyWords, ";")
      For i = LBound(vKeyWords) To UBound(vKeyWords)
        If InStr(sTextToSearch, vKeyWords(i)) > 0 Then
        iCentreToReceive = vKeyWords(i)
    Exit For
      End If
    Next i
   
    For Each objItem In objSel

        ' Forward to the specified mail address
        Set myForward = objItem.Forward
        myForward.Recipients.Add "LF, " & iCentreToReceive
        myForward.Send
        
    Next
    Set myForward = Nothing
    Set objItem = Nothing
End Sub

 
  06-Oct-2004  08:48   
Bob, see my response to your post at http://www.outlookcode.com/threads.aspx?forumid=2&messageid=7641
  13-Oct-2004  11:55   
Hi all,

I'm new in this site - lots of interesting info.
Sue, I'd like to kindly ask about the above code - I found another code you posted here -> http://www.winnetmag.com/MicrosoftExchangeOutlook/Article/ArticleID/27217/27217.html

The question is really simple - How should I create the macro, from scratch ? I actually need a beginner instructions, since I'm not familiar with VBA.
Where should I insert this code ? how to create a macro ? and how to make it run every time outlook 2003 starts ?

thanks,
Rollo
  13-Oct-2004  17:50   
Rollo, if you're new to Outlook VBA macros, these web pages should help you get started:

http://www.winnetmag.com/Articles/Index.cfm?ArticleID=21522&pg=1
http://www.outlookcode.com/d/vb.htm
 
Page [ 1 2 3 4 Next >>  
Post your comment



name        email