compile error : wrong number of arguments or invalid property assignment

I am getting compile error : wrong number of arguments or invalid property assignment in following piece of code

Sub SendEmail()

    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)

    olMail.To = "[email protected]"
    olMail.Subject = "Test Email"
    olMail.Body = "Hello. Welcome on board"
    olMail.Send

End Sub

Sub SendMassEmail()

Row_Number = 1

Do
DoEvents

    Row_Number = Row_Number + 1

    Call SendEmail(Sheet1.Range("A" & Row_Number), "This is a test email", Sheet1.Range("L1"))
    Loop Until Row_Number = 18
End Sub

Upvotes: 0

Views: 624

Answers (1)

user4039065
user4039065

Reputation:

You need to adjust the SendMail sub to accept the parameters you are feeding it.

Sub SendEmail(eml as string, sbj as string, bdy as string)

    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)

    olMail.To = eml
    olMail.Subject = sbj
    olMail.Body = bdy
    olMail.Send

End Sub

Sub SendMassEmail()

    Row_Number = 2

    Do while Row_Number <= 18
        Call SendEmail(Sheet1.Range("A" & Row_Number), "This is a test email", Sheet1.Range("L1"))
        Row_Number = Row_Number + 1
        DoEvents
    Loop

End Sub

Upvotes: 3

Related Questions