jackiesboy1986
Technical User
I am trying to help my work come up with a VBScript that will scan new emails with certain words in a subject. It gets the date and time of the appointment and automatically adds it to a public folder calendar. This is on an exchange server using outlook 2007. I am a newbie to VBScript but have found and modified several scripts to create the one below. The problem is that the script works fine for awhile (while I am testing it at the office) but then when I leave it stops working and I can't get it working again when I come back...Any ideas would be great...
Thanks in adavance
P.S. I am applying the script through a rule...if words in subject then run script:
Attribute VB_Name = "Module11"
Function GetFolder(FolderPath)
' folder path needs to be something like
' "Public Folders\All Public Folders\Company\Sales"
Dim aFolders
Dim fldr
Dim i
Dim objNS
On Error Resume Next
strFolderPath = Replace(FolderPath, "/", "\")
aFolders = Split(FolderPath, "\")
'get the Outlook objects
' use intrinsic Application object in form script
Set objNS = Application.GetNamespace("MAPI")
'set the root folder
Set fldr = objNS.Folders(aFolders(0))
'loop through the array to get the subfolder
'loop is skipped when there is only one element in the array
For i = 1 To UBound(aFolders)
Set fldr = fldr.Folders(aFolders(i))
'check for errors
If Err <> 0 Then Exit Function
Next
Set GetFolder = fldr
' dereference objects
Set objNS = Nothing
End Function
Sub NewMeetingRequest(meetingRequest As Outlook.MailItem)
Set objfolder = GetFolder("Public Folders\All Public Folders\Regional Calendars\The Calendar I Want Here")
' Create meetingRequest
Dim X As Integer
Dim Y As Integer
Dim startDay, startTime, endTime, bodystring As String
bodystring = meetingRequest.Body
' get meeting start day and time (line 7) preceded by "Appearance Date:"
X = InStr(bodystring, "Appearance Date:")
X = X + 17
startDay = Mid(bodystring, X, 10)
If (InStr(startDay, "T")) Then
startDay = Mid(bodystring, X, 9)
Else
startDay = startDay
End If
X = InStr(bodystring, "Appearance Time:")
X = X + 17
startTime = Trim(Mid(bodystring, X, 11))
calcEndTime = startTime
X = InStr(bodystring, "Person:")
X = X + 11
person = Trim(Mid(bodystring, X, 4))
Z = InStr(bodystring, "Other Person")
Z = Z + 15
otherperson = Trim(Mid(bodystring, Z, 75))
K = InStr(otherperson, vbCrLf)
otherperson = Mid(otherperson, 1, K)
Set gotoRequest = objfolder.Items.Add(olAppointmentItem)
gotoRequest.Body = meetingRequest.Body
gotoRequest.Subject = person & " - " & otherperson
gotoRequest.Start = startDay & " " & startTime
gotoRequest.End = startDay & " " & startTime
gotoRequest.ReminderSet = False
gotoRequest.Save
End Sub
Thanks in adavance
P.S. I am applying the script through a rule...if words in subject then run script:
Attribute VB_Name = "Module11"
Function GetFolder(FolderPath)
' folder path needs to be something like
' "Public Folders\All Public Folders\Company\Sales"
Dim aFolders
Dim fldr
Dim i
Dim objNS
On Error Resume Next
strFolderPath = Replace(FolderPath, "/", "\")
aFolders = Split(FolderPath, "\")
'get the Outlook objects
' use intrinsic Application object in form script
Set objNS = Application.GetNamespace("MAPI")
'set the root folder
Set fldr = objNS.Folders(aFolders(0))
'loop through the array to get the subfolder
'loop is skipped when there is only one element in the array
For i = 1 To UBound(aFolders)
Set fldr = fldr.Folders(aFolders(i))
'check for errors
If Err <> 0 Then Exit Function
Next
Set GetFolder = fldr
' dereference objects
Set objNS = Nothing
End Function
Sub NewMeetingRequest(meetingRequest As Outlook.MailItem)
Set objfolder = GetFolder("Public Folders\All Public Folders\Regional Calendars\The Calendar I Want Here")
' Create meetingRequest
Dim X As Integer
Dim Y As Integer
Dim startDay, startTime, endTime, bodystring As String
bodystring = meetingRequest.Body
' get meeting start day and time (line 7) preceded by "Appearance Date:"
X = InStr(bodystring, "Appearance Date:")
X = X + 17
startDay = Mid(bodystring, X, 10)
If (InStr(startDay, "T")) Then
startDay = Mid(bodystring, X, 9)
Else
startDay = startDay
End If
X = InStr(bodystring, "Appearance Time:")
X = X + 17
startTime = Trim(Mid(bodystring, X, 11))
calcEndTime = startTime
X = InStr(bodystring, "Person:")
X = X + 11
person = Trim(Mid(bodystring, X, 4))
Z = InStr(bodystring, "Other Person")
Z = Z + 15
otherperson = Trim(Mid(bodystring, Z, 75))
K = InStr(otherperson, vbCrLf)
otherperson = Mid(otherperson, 1, K)
Set gotoRequest = objfolder.Items.Add(olAppointmentItem)
gotoRequest.Body = meetingRequest.Body
gotoRequest.Subject = person & " - " & otherperson
gotoRequest.Start = startDay & " " & startTime
gotoRequest.End = startDay & " " & startTime
gotoRequest.ReminderSet = False
gotoRequest.Save
End Sub