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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

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,487
Messages
5,408,554
Members
403,215
Latest member
DblDocWhitaker

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top