[RESOLVED] [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
Hi All:wave:
I want to create a Batch File when some specific message arrives in my Outlook Box.
The Format of Batch File will be Fixed always, only things which will change is Date (Which it will pick From Email Subject) and Location which it will pick from Message body.
For Example:
Email Subject: Run Batch File on 2502 Next Month (Or Run Batch File Next Month On 2502)
Message Body:
Blah Blah Blah.....
Location: "C:\Temp\OlTest"
Then once this message comes it must create a Batch File as follows:
@Echo Off
@cd C:\Temp
@xcopy C:\Temp\Install_2502_File.zip C:\Temp\OlTest
Exit
Next Time when message comes with Subject: Run Batch File on 1603 Next Month
Message Body: Blah Blah Blah....
Location: "NewLocation"
It must create Batch File as (It would also help if it edit the values in existing batch file)
@Echo Off
@cd C:\Temp
@xcopy C:\Temp\Install_1603_File.zip <NewLocation>
Exit
Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
Do anyone have idea about this?
Or Else,
Will it work if I give output to a Notepad and then rename it as batch File
i.e. I will create a file NewText.txt and then I will rename it as NewText.bat
Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
No need to create a file NewText.txt and renaming it as NewText.bat...
You can directly write to NewText.bat. It is the same as writing to text file. Search the forum and you will find plenty of examples on how to write to a text file. :)
Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
I tried the following code to edit an existing batch File
Code:
Dim iFileNo As Integer
iFileNo = FreeFile
'OPen the file for writing
Open "\\" & strServer & "\c$\WINDOWS\system32\Framework32.bat" For Output As #iFileNo '--> strServer Value I am picking from Email Subject Line
Print #iFileNo, "@echo off"
Print #iFileNo, "REM Batch Modification Testing"
Print #iFileNo, "REM Sample Script Testing"
Print #iFileNo, "@ cd D:\"
Print #iFileNo, "@ D:"
Print #iFileNo, "@ mkdir TestDir"
Print #iFileNo, "@ cd D:\TestDir"
Print #iFileNo, ""
Close #iFileNo
How can I pick the location from Message Body, For Example:
Ex 1: Location: C:\Temp\
Ex 2: Blah Blah Blah....
Location:C\Temp
Ex 3: Location:C\Temp
Blah Blah Blah.....
Ex 4: Blah Blah Blah...
XXXXXXXXXX Location: C:\Temp
Blah Blah Blah
In all the four examples above I want to pick the Location (C:\Temp\). THe thing which is common on all the four example are "C:\Temp" is always coming after word "Location", but it is also not fixed that how many spaces are in between "Location" and "C:\Temp\" Or on which line of message body will it appear.
Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
Now I see that you are doing good on your own which is very good so here is a hint on how to tackle this situation :)
Read up on Split() and Instr() ;)
If you get stuck you know what to do.... :)
Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox
Hi SID,
I think I got a way to do that by using following code:
Code:
Sub ParseTextLine()
Dim objOL As Outlook.Application
Dim objItem As Object
Dim strAddr As String
On Error Resume Next
Set objOL = Application
Set objItem = objOL.ActiveExplorer.Selection(1)
If Not objItem Is Nothing Then
strAddr = ParseTextLinePair(objItem.Body, "Location:")
If strAddr <> "" Then
MsgBox strAddr
Else
MsgBox "Could not extract address from message."
End If
End If
Set objOL = Nothing
Set objItem = Nothing
End Sub
To make that code work, I have to define function ParseTextLinePair as shown below.
Code:
Function ParseTextLinePair _
(strSource As String, strLabel As String)
Dim intLocLabel As Integer
Dim intLocCRLF As Integer
Dim intLenLabel As Integer
Dim strText As String
intLocLabel = InStr(strSource, strLabel)
intLenLabel = Len(strLabel)
If intLocLabel > 0 Then
intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
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
Thanks for all your help SID.
It's really fun to learn things here on this Forum.