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)
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 ******************************************************************************* '**************************************************************************************
|
|
|
|
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)
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?
|
|
|
|
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)
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
|
|
|
|
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)
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.
|
|
|
|
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)
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?
|
|
|
|