Run-time error '424': Object required, email on button click with selected cell values

mikura

New Member
Joined
Dec 28, 2013
Messages
11
Please Help!
I included a code for send emails on button click with multiple cell values which comes in column A and B. These column are selected using dynamically generated checkboxes.
I’m able to create dynamic checkboxes but I failed to retrieve the cell values to a variable.
While I’m running the code debugger is giving a message "Run-time error '424': Object required".
I’m a beginner in excel vba. Please help me.:(
Code:
Sub previewmails()
Dim counter As Integer
Dim strSku As Long
Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration
If chkbx.Value = 1 Then
    counter = 1
For r = 1 To counter
        If Cells(r, 1).Top = chkbx.Top Then
                counter = counter + 1
       
                        strSku = Cells(Target.row, "B").Value & " (" & Cells(Target.row, "A").Value & "), "
                    Exit For
                End If
              
            Next r
        End If
   
                Config(cdoSendUsingMethod) = cdoSendUsingPort
                Config(cdoSMTPServer) = "smtp.gmail.com"
                Config(cdoSMTPServerPort) = 465
                Config(cdoSMTPAuthenticate) = cdoBasic
                Config(cdoSMTPUseSSL) = True
                Config(cdoSendUserName) = "test@mail.com"
                Config(cdoSendPassword) = "password@123"
                Config.Fields.Update
               
                Mail.To = "test@mail.com"
                Mail.From = Config(cdoSendUserName)
                Mail.Subject = "Email Subject"
                Mail.HTMLBody = "<b>" & strSku & "</b>"
               
               
                On Error Resume Next
               
                Mail.Send
               
                If Err.Number <> 0 Then
                MsgBox Err.Description, vbCritical, "There was an error"
                Exit Sub
                End If
                MsgBox "Your email has been sent!", vbInformation, "Sent"
                     
 
                End Sub


Any help much appreciated as ever!

Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It would help if you tell us on what line of code the error occurs at run-time.
 
Upvote 0
Thanks for your quick response.

I getting only this error message. But I'm sure error is in this part.

If chkbx.Value = 1 Then
counter = 1
For r = 1 To counter
If Cells(r, 1).Top = chkbx.Top Then
counter = counter + 1

strSku = Cells(Target.row, "B").Value & " (" & Cells(Target.row, "A").Value & "), "
Exit For
End If

Next r
End If

where I'm trying to retrieve the cell values because I'm able to send test emails with the remaining code.
 
Upvote 0
What line of code is colored yellow at the moment of getting the 424 error message? It has to be some line...
Also, use F8 to step through the code and see yourself what happens (or what does not happen but what should happen).
 
Upvote 0
comment out "on error resume next" line

just put an apostrophe (single quote) before the text on the line " ' on error resume next"

that should keep the error from becoming invisible


which reference file do you have loaded for this?

Dim Mail As New Message
 
Last edited:
Upvote 0
It is highlighting 7th code line "If chkbx.Value = 1 Then"

Microsoft CDO for Windows 2000 library is the reference file I have loaded for "Dim Mail As New Message"
 
Last edited:
Upvote 0
What does chkbx refer to? Are you using a userform, or a sheet, or .... ?
 
Upvote 0
Chkbx are dynamic checkbox for active cells which I'm creating through
Sub Addcheckboxes()Dim cell, LRow As Single
Dim chkbx As CheckBox
Dim MyLeft, MyTop, MyHeight, MyWidth As Double


Application.ScreenUpdating = False
LRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).row


For cell = 2 To LRow
If Cells(cell, "A").Value <> "" Then
MyLeft = Cells(cell, "H").Left
MyTop = Cells(cell, "H").Top
MyHeight = Cells(cell, "H").Height
MyWidth = Cells(cell, "H").Width
ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight).Select
With Selection
.Caption = ""
.Value = xlOff
.Display3DShading = False
End With
End If
Next cell


Application.ScreenUpdating = True


End Sub

And I'm removing these checkboxes using this code
Sub RemoveCheckboxes()

ActiveSheet.CheckBoxes.Delete

End Sub
These codes are working fine.

I'm using a sheet not userform.
 
Upvote 0

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top