outlook 2007 custom VBA script does not work.

Author Message
Tripteo

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 9/25/2010
  • Status: offline
outlook 2007 custom VBA script does not work. Sunday, September 26, 2010 12:02 AM (permalink)
0
Hi all,
 
I had a friend of mine writing a script in VBE that would
run while I am out of my office and automatically respond
to quotes that I receive from a specific web site with a template.
So the title and subject of the emails is always the same,
in the emails content is an email address of a customer
that the template should be forwarded to but for some reason it
does not run and just put the new emails in my inbox folder.
Any help with this issue would be greatly appreciated.
 
P.s : I am a Noob
 
See here the script :
 
 
 
Option Explicit
 
'** GLOBALS *********************************************************************************
'' SECTION START
'' CHANGE THE VALUES IN BETWEEN THE DOUBLE QUOTES IF NEEDED

'' Response Email Template Name
Set strTemplate = "QuoteResponse.oft"

'' Response Email Subject
Set strResponseEmailSubject = "Preliminary Quote"

'' Final Output Folder to put emails into after processing (replied to)
Set strOutputFolder = "AutoRepliedQuotes"

'' Email address of the originating email
Set strSenderAddress = "admin@compare-quotes.com.au"

'' END SECTION
Dim myOutlook, OutlookNameSpace, inputFolder, outputFolder 'objects
Dim iCtr
Dim myResponseEmail, strInputFolder, strOutputFolder, strMsgBody, strEmailContents
 
'** MAIN ************************************************************************************
Public Sub main(outlookMessage As Outlook.mailItem)
                           
    ' hook into outlook
    Set myOutlook = CreateObject("Outlook.Application")
    Set OutlookNameSpace = myOutlook.GetNamespace("MAPI")
    ' Get all top level folders and find our target email folder....
    For iCtr = 1 To OutlookNameSpace.Folders.Item(1).Folders.Count
        If LCase(OutlookNameSpace.Folders.Item(1).Folders(iCtr).Name) = LCase(strOutputFolder) Then
            'found our output folder :)
            Set outputFolder = OutlookNameSpace.Folders.Item(1).Folders(iCtr)
        End If
    Next
    If outlookMessage.SenderEmailAddress = strSenderAddress Then

        
        strMsgBody = outlookMessage.Body  ' assign message body to a variable
       
        strEmailContents = strEmailContents & ParseTextLinePair(strMsgBody, "Email")

      
        Set myResponseEmail = myOutlook.CreateItemFromTemplate("C:\Program Files\Microsoft Office\Templates\" + strTemplate)
        myResponseEmail.To = strEmailContents
        myResponseEmail.Subject = strResponseEmailSubject
        myResponseEmail.Send
        ' move it to another folder
        outlookMessage.Move (outputFolder)
    End If
End Sub
 
'** FUNCTIONS ******************************************************************************
Function ParseTextLinePair(strSource, strLabel)
   
    Dim intLocLabel
    Dim intLocCRLF
    Dim intLenLabel
    Dim strText
    intLocLabel = InStr(strSource, strLabel)
    intLenLabel = Len(strLabel)
    If intLocLabel > 0 Then
        intLocCRLF = InStr(intLocLabel, strSource, " ")
        If intLocCRLF > 0 Then
            intLocLabel = intLocLabel + intLenLabel
            strText = Mid(strSource, intLocLabel, intLocCRLF - intLocLabel)
        Else
            intLocLabel = Mid(strSource, intLocLabel + intLenLabel)
        End If
    End If
   
    ParseTextLinePair = Trim(strText)
   
End Function
'** EOF *******************************************************************************
'**************************************************************************************
 
 
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:outlook 2007 custom VBA script does not work. Monday, September 27, 2010 1:25 AM (permalink)
    0
    So the code as it is written now is VBA not VBScript. VBE by the way the the acronym for VBScript Encoder which is not actually a language at all. Which language do you actually want to use?
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      Tripteo

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 9/25/2010
      • Status: offline
      Re:outlook 2007 custom VBA script does not work. Monday, September 27, 2010 2:18 AM (permalink)
      0
      hi ebgreen,
       
      This is going to sound confusing.
      Well it has been written in VBE (visual basic editor) in ms outlook2007. And the plan was that this script should automaticly respond to any emails that come in from "compare-quotes" (website providing me leads) open the email and extract the email address provided in the compare-quotes email and send back a teplate.
      The guy who helped me write the script is overseas now and cannot help me.
       
      Cheers
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:outlook 2007 custom VBA script does not work. Monday, September 27, 2010 3:00 AM (permalink)
        0
        Ok, so the editor does not necessarily define the language used. In this case it sounds like the first issue that you have is getting the code to run for each incoming message. So in outlook go to Tools->Rules and alerts and create a rule that runs this code for every incoming message.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          Tripteo

          • Total Posts : 3
          • Scores: 0
          • Reward points : 0
          • Joined: 9/25/2010
          • Status: offline
          Re:outlook 2007 custom VBA script does not work. Tuesday, September 28, 2010 7:36 PM (permalink)
          0
          Hi ebgreen,
           
           
          Yeah thats the issue, i have got it all set up in the oulook rule that when i recieve a email from "compare-quotes"
          to run the script and auto reply with my template but it does not start when the emal comes in.
          So Im not sure what im doing wrong if there something wrong in the script or if Im missing something else?
           
           
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9