How to find till which row the marco executed. It stopped at some random row without any error and unable to identitfy at what row it has been stopped

parrykrish

New Member
Joined
Aug 30, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I've the below code to create outlook teams invite, when i excute it it stops at random 40+ row but I've 200+ invites to be sent on daily basis.



1. Please help me with this code where I went wrong

2. I want a msgbox stating till which row macro has executed.



VBA Code:
Option Explicit

Sub SetApptWithHTMLContent()

    Dim olapp As Outlook.Application, appt As Outlook.AppointmentItem
    Dim m As Outlook.MailItem
    Dim rtf() As Byte
    Dim ml1 As Worksheet
    Dim r As Long
    Dim j As Long
    Dim sh As Worksheet
    Set sh = Sheets("Scheduler")
    Dim startline As String
    Dim t As Long

    r = 2

Do

    Set olapp = New Outlook.Application
    Set m = olapp.CreateItem(olMailItem)
    Set appt = olapp.CreateItem(olAppointmentItem)

On Error Resume Next

    appt.Subject = "Interview with '" & sh.Cells(r, 3).Value & "' for '" & sh.Cells(r, 4).Value & "' - " & sh.Cells(r, 2).Value & " | on " & Format(sh.Cells(r, 6).Value, "DD-MMM-YYYY") & " at " & Format(sh.Cells(r, 5).Value, "hh:mm AM/PM")

    appt.Recipients.Add sh.Cells(r, 9).Value
    appt.OptionalAttendees = sh.Cells(r, 10).Value
    appt.Start = sh.Cells(r, 6).Value + sh.Cells(r, 5).Value
    appt.End = sh.Cells(r, 8).Value + sh.Cells(r, 7).Value
    appt.Location = "Microsoft Teams Meeting"

    '...set other appointment properties
    appt.Display
    'put the HTML into the mail item, then copy and paste to appt
    m.BodyFormat = olFormatHTML
    m.HTMLBody = "<Body style = font-size:12pt, fornt-familt:Arial>" & "Dear " & sh.Cells(r, 2).Value & "," & "<br> Greetings from  " & sh.Cells(r, 3).Value & "<p><b><u> Note:</b></u> Please make sure the internet connection and also join through the Laptop." & "<br> You are invited for LIVE video interview as per the below schedule for '" & sh.Cells(r, 4).Value & "' role. <p><b> Topic:</b> " & "Interview with '" & sh.Cells(r, 3).Value & "' for " & "'" & sh.Cells(r, 4).Value & "'" & "<br><b> Time:</b> " & Format(sh.Cells(r, 6).Value, "DD-MMM-YYYY") & " at " & Format(sh.Cells(r, 5).Value, "hh:mm AM/PM") & "<p> Kindly accept the invite and make yourself free to attend the interview, Please feel free to reach out to our team for any clarification required. <p>Thanks and regards <br> Meedenlabs Team on behalf of " & sh.Cells(r, 3).Value

    appt.Attachments.Add sh.Cells(r, 12).Value

    m.GetInspector().WordEditor.Range.FormattedText.Copy
    appt.GetInspector().WordEditor.Range.FormattedText.Paste

    'Send Keys to convert Calendar invite to MS Teams invite
    SendKeys "{F10}", True
    SendKeys "h", True
    SendKeys "y1", True
    SendKeys "{ENTER}", True

    m.Close False 'don't save...
    r = r + 1
    startline = ""
Loop While Len(sh.Cells(r, 9).Value) > 5

End Sub

1725008605689.png
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You could add a line with
VBA Code:
debug.print r
and inspect the immediate pane to see what the last number was?
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi, also, temporarily (or IMO permanently) - remove or comment out this line On Error Resume Next as it's masking any errors you might be getting.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,082
Members
453,021
Latest member
Justyna P

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