1

If have a function that loops through a selection of emails, an email is an object not a lose variable (Passing variable from Form to Module in VBA):

Private Sub CommandButton5_Click()

For Each objItem In Application.ActiveExplorer.Selection
    moveMail(TextBox1.Value, objItem)
Next
End Sub

based on - lets say - the subject I want to do something with that email. That means that I will have to move the mail object to a function. But if do like I did it now I get an error.

compiling error    
synstaxt error
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

-1

It is possible, you just need to be more careful declaring your variables.

Sub schaap()
For Each objItem In Application.ActiveExplorer.Selection
    Dim mailbericht As Object
    Set mailbericht = objItem
    Call cavia(mailbericht)
Next
End Sub

Function cavia(mailbericht As Object)
    MsgBox mailbericht.Subject
End Function