PDA

View Full Version : save email using subject and wildcards



CAMinTheToon
08-15-2008, 02:18 AM
Hi,

I am trying to save a email to specific folders based on the email subject.

I have the following code.

I can get it to work if the email subject is only ?H1221? if the subject is ?H1221 Delivery Dates? then it stops working I have tried using wildcards * & ? but this does not seem to work? Any help would be greatly appreciated.



Sub SaveAs_msg()

Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the item? If a file with the same name already exists, it will be overwritten with this copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then

'objItem.SaveAs "C:\" & strname & ".msg", olMSG

'If objItem.Subject = "H1221" Then ? this work if subject is only ?H1221

If objItem.Subject = "H1221 *" Then ? this is meant to work if the subject is ?H1221 delivery dates?

objItem.SaveAs "Z:\H1221\" & strname & ".msg", olMSG

End If
End If
Else
MsgBox "There is no current active inspector."

End If


End Sub


Many thanks,

Colin,

Mavyak
08-15-2008, 06:29 AM
Change this:
If objItem.Subject = "H1221 *" Then ‘ this is meant to work if the subject is “H1221 delivery dates”

To either this:
If InStr(objItem.Subject, "H1221") > 0 Then ‘ this is meant to work if the subject is “H1221 delivery dates”

or this:

If Left(objItem.Subject, 5) = "H1221" Then ‘ this is meant to work if the subject is “H1221 delivery dates”