Hello everyone,

This is my first post on this forum, so im glad to meet you experts .
Please help me with following my code.
It's part of code. Everything works, except one thing.
When we open dialog popup and choosing path, VBA is searching for all documents with *.pdf extension.
In order to name of file, code should send email with attached document to recipients.
If code finds "2222" in part of name file, email should go to company no 2. If code finds "1111", email should be send to another receiver.
But it doesnt work properly. It's only send 1 email (number 33333), but it should send all 3 emails (because I put 3 documents in folder with names: "11111", "22222" and "33333").

Can you help me and tell me where is mistake in my code? Im newbie at VBA so I will be grateful for forgiving attitude.


PHP Code: 
   Do While xFname$ <> ""
      
     
If InStr(1xFname$, "11111"vbTextCompare) > 0 Then
                    Temat 
"Company 1111"
                    
Tresc "ple ple 1"
                       
MsgBox ("Sent to company 11111")


                    ElseIf 
InStr(1xFname$, "22222"vbTextCompare) > 0 Then
                            Temat 
"Company 2222"
                            
Tresc "ple ple 2"
                              
MsgBox ("Sent to company 22222")
                            

                            ElseIf 
InStr(1xFname$, "33333"vbTextCompare) > 0 Then
                              Temat 
"Company 3333"
                              
Tresc "ple ple 3"
                                     
MsgBox ("Send to company 33333")



                    
             
End If
             
On Error Resume Next
            With OutMail
                                 
.To "my@mail.com"
                                 
.CC ""
                                 
.BCC ""
                                 
.Subject Temat
                                 
.HTMLBody Tresc
                                 
.Attachments.Add ("C:\Users\plmackry\Desktop\testowy folder\565389963_33333.pdf")
                                 .
Display
                                 
.Send
                                     MsgBox 
("Tresc")
                                 
End With
                                 
                                 


         ActiveCell
.Offset(xRow) = xFname$
         
xRow xRow 1
         xFname
$ = Dir
                  xDirect
$ = .SelectedItems(1) & "\"
     Loop
   End If
   End With
  On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing