sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm getting 2 errors in the same module, which I think are connected.
The first one I get is 'Error 424 Object required' and this fails on line 40. The 2nd one I get is 'Error 91 Object variable or With block variable not set', which fails on line 140.
I've posted both in the same question because I strongly suspect they are linked - can anyone confirm and suggest a way to resolve it?
The first one I get is 'Error 424 Object required' and this fails on line 40. The 2nd one I get is 'Error 91 Object variable or With block variable not set', which fails on line 140.
I've posted both in the same question because I strongly suspect they are linked - can anyone confirm and suggest a way to resolve it?
Code:
Dim Rng As RangeDim Rng2 As Range
Dim OL As Object
Dim EmailItem As Object
10 Set Rng = Nothing
20 Set Rng2 = Nothing
30 Set Rng = Sheet16.Range("A1:E27").SpecialCells(xlCellTypeVisible)
40 Set Rng2 = Sheet16.Range("A29:D31").SpecialCells(xlCellTypeVisible)
50 With Application
60 .EnableEvents = False
70 .ScreenUpdating = False
80 End With
90 Set OL = OutlookApp(olMaximized)
100 Set EmailItem = OL.CreateItem(olMailItem)
110 With EmailItem
120 .Subject = "Duty - " & Sheet8.Range("B2").Value & " Team " & Sheet8.Range("B3").Value & " (" & Sheet8.Range("B13").Value & " Shift " & Sheet8.Range("B17").Value & ")"
130 If Sheet16.Range("G1").Value = "YES" Then
140 .HTMLBody = RangetoHTML(Rng2) & RangetoHTML(Rng)
150 Else
160 .HTMLBody = RangetoHTML(Rng)
170 End If
180 .To = "Duty Mailbox"
190 .CC = ""
200 .BCC = ""
210 .Display
220 End With
230 Set OL = Nothing
240 Set EmailItem = Nothing
250 With Application
260 .EnableEvents = True
270 .ScreenUpdating = True
280 End With