0

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.