VBA - label not defined (GoTo)

Alono23

New Member
Joined
Jan 20, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi there,

So i have below code and error ("label not defined"). not sure where i need to put the Exit Sub.
appreciate your help here.

VBA Code:
Private Sub Workbook_Open()

    Dim r As Range
    Dim cell As Range

    Set r = Range("A2:A400")

    For Each cell In r

        If cell.Value - 2 = Date Then
       
            Dim Email_Subject, Email_Send_From, Email_Send_To, _
            Email_Cc, Email_Bcc, Email_Body As String
            Dim Mail_Object, Mail_Single As Variant

       
            Email_Subject = cell.Offset(, 4).Value
            Email_Send_From = "a@aaa.com"
            Email_Send_To = "T@Test.com"
            Email_Cc = ""
            Email_Bcc = ""
            Email_Body = cell.Offset(, 5).Value
           
            'Exit Sub
           
           
            On Error GoTo debugs
            Set Mail_Object = CreateObject("Outlook.Application")
            Set Mail_Single = Mail_Object.CreateItem(0)
            With Mail_Single
            .Subject = Email_Subject
            .To = Email_Send_To
            .cc = Email_Cc
            .BCC = Email_Bcc
            .Body = Email_Body
            '.send
            .display
   
            End With
        End If
    Next
   
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You've got On Error Goto debugs but you have no such label. Add debugs: wherever you want the code to jump to.
 
Upvote 0
You've got On Error Goto debugs but you have no such label. Add debugs: wherever you want the code to jump to.
Thanks for the quick reply !
Just tried but think i'm doing it incorrectly.. can you assist with editing the code to solve this error?

Many thanks,
 
Upvote 0
I suspect you just want the code to finish, so put that line before the End Sub line.
 
Upvote 0
I suspect you just want the code to finish, so put that line before the End Sub line.
I did. same error. i have removed this line entirely and seems the code works fine.
This code generate Auto email once due date is approaching (2 days before Today). can I add additional rule to this code and saying "If email was sent [assuming need to set additional column with Y/N], so no need to send again" ?

the end goal to loop on the table and see where there is a line with Today-2, then send the email according to the parameters in the code..

Hope it's clear.

Many thanks Again.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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