Consulting

Results 1 to 2 of 2

Thread: save email using subject and wildcards

  1. #1

    save email using subject and wildcards

    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,

  2. #2
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    Change this:
    [VBA]If objItem.Subject = "H1221 *" Then ‘ this is meant to work if the subject is “H1221 delivery dates”[/VBA]

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

    or this:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •