1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Ms Outlook 2007 custom script does not run?

Discussion in 'Business Applications' started by tripteo, Sep 26, 2010.

Thread Status:
Not open for further replies.
  1. tripteo

    tripteo Thread Starter

    Joined:
    Sep 26, 2010
    Messages:
    2
    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.
    Here is 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 = "[email protected]"
    '' 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
    Rem If outlookMessage.SenderEmailAddress = "[email protected]" Then

    strMsgBody = outlookMessage.Body ' assign message body to a variable

    strEmailContents = strEmailContents & ParseTextLinePair(strMsgBody, "Email")
    Rem strEmailContents = "[email protected]"

    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 *******************************************************************************
    '**************************************************************************************
     
  2. HiTechCoach

    HiTechCoach

    Joined:
    Jul 14, 2010
    Messages:
    145
    Where and how are you running this VBA code?
     
  3. tripteo

    tripteo Thread Starter

    Joined:
    Sep 26, 2010
    Messages:
    2
    I run it in outlook 2007 as a script. and the template is saved in the ms office template folder.
    so i made a rule that when i recieve a email from that specific company it should automaticly run the script and send back my template.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/952445

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice