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
 
And where in the code do you fill that variable called Chkbx ? :)
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I included "Dim chkbx As CheckBox" but now debugger is giving a message "Run-time error '91' :Object variable or block variable not set" and highlighting "If chkbx.Value = 1 Then". :confused:
 
Upvote 0
Declaring is not enough. With declaring, your reserve a little bit of memory for that variable.
But you do not fill that variable. You do not assign that variable a valid checkbox. So it's null and you cannot work with it in your code (it gives an error because it's not assigned a checkbox object).
 
Upvote 0
Ok. Now I modified the code with a "for each" function
Dim counter As IntegerDim strSku As Long


Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration


For Each chkbx In ActiveSheet.CheckBoxes
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
Next

And I tried to send "strsku" in the body of the email. But I received just "0".
 
Upvote 0
Your counter variable is 1, so your inner loop will only be done for r = 1.
Is that correct?
 
Upvote 0
Yes you are right.

I modified my for loop by "For r = 1 To Rows.Count". Now it is again showing Run-time error '424' and highlighting "strSku = Cells(Target.row, "B").Value & " (" & Cells(Target.row, "A").Value & "), ""
 
Upvote 0
Mikura

And where do you define / fill the variable Target?

Again, you cannot use variables if you do not fill them...

Man, this is getting frustrated...
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,704
Members
449,118
Latest member
MichealRed

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