Goo morning, All.
I have routine below which I wrote with the help of some of you guys :).
It was working perfectly yesterday and today it has decided not to work.
The routine stops at:
--> wdDoc.Range.InsertBefore vbNewLine with the error message: Run-Time Error '91': Object variable or With block variable not set.
VBA Code
Sub sendcomplexemailattachment()
Dim olApp As Object 'Outlook.Application
Dim olEmail As Object 'Outlook.MailItem
Dim olInsp As Object 'Outlook.Inspector
Dim olAttachments As Object 'Outlook.Attachments
Dim wdDoc As Object 'Word.Document
Dim wdRng As Object 'Word.Range
On Error Resume Next
Set olApp = GetObject(, "outlook.application")
If Err <> 0 Then Set olApp = CreateObject("outlook.application")
On Error GoTo 0
Set olEmail = olApp.CreateItem(0)
Set olAttachments = olEmail.Attachments
With olEmail
.BodyFormat = 3
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
.To = "WE CFR REPORT"
.Subject = "WE CFR DAILY REPORT" & " - " & Format(Date, " dd.mm.yy")
wdDoc.Range.InsertBefore vbNewLine
Sheets("SAP BO Cuts").Range("A1").CurrentRegion.Copy
Set wdRng = wdDoc.Range
wdRng.Collapse Direction:=1 'wdCollapseStart
wdRng.MoveStart Unit:=1, Count:=1 'Unit:=wdCharacter
wdRng.Paste
wdDoc.Range.InsertBefore vbNewLine & vbNewLine & "Past days cuts:"
olAttachments.Add "L:\MMO\Scorecard\1. CFR Results\Total Hair WE CFR Report.xls", _
1, 1, "Total Hair WE CFR Report"
wdDoc.Range.InsertBefore vbNewLine & vbNewLine & "CFR MDO/Plants:" & vbNewLine
Sheets("Summary").Range("A1:F7").Copy
Set wdRng = wdDoc.Range
wdRng.Collapse Direction:=1 'wdCollapseStart
wdRng.PasteSpecial DataType:=4 'wdPasteBitmap
wdDoc.Range.InsertBefore "CFR MTD:" & vbNewLine & vbNewLine
wdDoc.Range.InsertBefore "Good Morning, All." & vbNewLine & vbNewLine & "Please see below latest CFR results and cuts." & vbNewLine & vbNewLine
.Display
End With
End Sub
Any ideas what could be causing this issue, please?
I tried to change the reference list priority but no lick.
Thank you very much for your help in advance.
Best regards,
Vanessa Simmonds
<Mod. Moved to Office Programming>