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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
It would help if you tell us on what line of code the error occurs at run-time.
 

mikura

New Member
Joined
Dec 28, 2013
Messages
11
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.
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
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).
 

jsotola

Well-known Member
Joined
Nov 15, 2013
Messages
524
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:

mikura

New Member
Joined
Dec 28, 2013
Messages
11
Microsoft CDO for Windows 2000 library
 

mikura

New Member
Joined
Dec 28, 2013
Messages
11
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:

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
What does chkbx refer to? Are you using a userform, or a sheet, or .... ?
 

mikura

New Member
Joined
Dec 28, 2013
Messages
11
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.
 

Forum statistics

Threads
1,089,210
Messages
5,406,868
Members
403,109
Latest member
gamer527

This Week's Hot Topics

Top