Results 1 to 4 of 4

Thread: How does OR in VBA work?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How does OR in VBA work?

    Hello there,

    I wrote the following code:

    Sub Search_Move_Email()
        Dim olItem As Outlook.MailItem
        Dim MailItem As Outlook.MailItem
        Dim sText As String
        Dim myNameSpace As Outlook.NameSpace
        Dim myDestFolder As Outlook.MAPIFolder
        Dim mySearchFolder As Outlook.MAPIFolder
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set myDestFolder = myNameSpace.Folders("root").Folders("archiv")
        Set mySearchFolder = myNameSpace.Folders("root").Folders("alert-check")
    For Each MailItem In mySearchFolder.Items
            Set olItem = MailItem
            sText = olItem.Body
    If (InStr(1, sText, "no rows selected", vbTextCompare) > 0) Or (InStr(1, sText, "Es wurden keine Zeilen ausgewählt", vbTextCompare) > 0) Then
                olItem.Move myDestFolder
            End If
        Next
    End Sub
    The code is indeed working. But I have to run "serveral times" to move the emails to the archiv folder. The script will firstly move Emails whose body contains "now rows selected". In the 2nd and 3rd run (?it is also strange that I need 3 runs), it will then move Emails whose body contains "Es wurden keine Zeilen ausgewählt".

    It seems that the OR doesn't work in VBA?
    Thank you for any hints.

    Best regards
    CC
    Last edited by Aussiebear; 10-24-2023 at 03:27 AM. Reason: Added code tags to supplied code

Tags for this Thread

Posting Permissions

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