I am getting a "Run-Time Error 91 Object variable or With block variable not set" error. The code worked once or twice and, after that, it stopped working.
Can anyone help with what I am doing incorrectly?
I am getting the error with the following code, on the lines indicated below:
Private Sub CommandButton1_Click()
Dim Sht As Excel.Worksheet
Set Sht = ThisWorkbook.ActiveSheet
Recip = Worksheets("STIF Report").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 6) ----!
Custody = Worksheets("STIF Report").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 5) ----!
Dim rng As Range
Set rng = Sht.Range("B43:D85")
rng.Copy
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
Dim vInspector As Object
Set vInspector = OutMail.GetInspector
Dim wEditor As Object
Set wEditor = vInspector.WordEditor
With OutMail
.TO = Recip
.CC = ""
.Subject = "STIF Vehicle Confirmation" & " - " & Custody ----!
.display
wEditor.Paragraphs(1).Range.Text = "Hello All," & Chr(11) & Chr(11) & "I hope this email finds you all doing well." & Chr(11) & Chr(11) & _
"Can you please confirm if the below STIF vehicle details are accurate for the accounts below? If the vehicle has changed, can you please confirm the new STIF vehicle name and CUSIP?" & vbCrLf
wEditor.Paragraphs(2).Range.Paste
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub