I have this code that copies and pastes a picture into an an email. It works 90% of the time, I cannot find the reason why sometimes I get a run-time error. I close out excel and wait a few minutes and then open the sheet up again and it then works.
Set wdDoc = Email.GetInspector.WordEditor
Run-time error `-2147467259 (80004005)':
The Operation Failed
Set wdDoc = Email.GetInspector.WordEditor
Run-time error `-2147467259 (80004005)':
The Operation Failed
VBA Code:
Public Sub ScreenShotResults4_with_Current()
Dim Rng As Range
Dim olApp As Object
Dim Email As Object
Dim Sht As Excel.Worksheet
Dim wdDoc As Word.Document
ActiveSheet.Shapes("Row1Circle").Visible = False
ActiveSheet.Shapes("Row2Circle").Visible = False
ActiveSheet.Shapes("Row3Circle").Visible = False
ActiveSheet.Shapes("Row4Circle").Visible = False
ActiveSheet.Shapes("Row5Circle").Visible = False
ActiveSheet.Shapes("Row6Circle").Visible = False
ActiveSheet.Shapes("Row7Circle").Visible = False
ActiveSheet.Shapes("Row8Circle").Visible = False
ActiveSheet.Shapes("Row9Circle").Visible = False
ActiveSheet.Shapes("Row10Circle").Visible = False
ActiveSheet.Shapes("Row11Circle").Visible = False
ActiveSheet.Shapes("Row12Circle").Visible = False
ActiveSheet.Shapes("Apps1Circle").Visible = False
ActiveSheet.Shapes("Apps2Circle").Visible = False
ActiveSheet.Shapes("Apps3Circle").Visible = False
ActiveSheet.Shapes("Apps4Circle").Visible = False
ActiveSheet.Shapes("Apps5Circle").Visible = False
ActiveSheet.Shapes("Apps6Circle").Visible = False
ActiveSheet.Shapes("Apps7Circle").Visible = False
ActiveSheet.Shapes("Apps8Circle").Visible = False
ActiveSheet.Shapes("Apps9Circle").Visible = False
ActiveSheet.Shapes("Apps10Circle").Visible = False
ActiveSheet.Shapes("Apps11Circle").Visible = False
ActiveSheet.Shapes("Apps12Circle").Visible = False
ActiveSheet.Shapes("Fund1Circle").Visible = False
ActiveSheet.Shapes("Fund2Circle").Visible = False
ActiveSheet.Shapes("Fund3Circle").Visible = False
ActiveSheet.Shapes("Fund4Circle").Visible = False
ActiveSheet.Shapes("Fund5Circle").Visible = False
ActiveSheet.Shapes("Fund6Circle").Visible = False
ActiveSheet.Shapes("Fund7Circle").Visible = False
ActiveSheet.Shapes("Fund8Circle").Visible = False
ActiveSheet.Shapes("Fund9Circle").Visible = False
ActiveSheet.Shapes("Fund10Circle").Visible = False
ActiveSheet.Shapes("Fund11Circle").Visible = False
ActiveSheet.Shapes("Fund12Circle").Visible = False
ActiveSheet.Shapes("Fund12Circle").Visible = False
Sheets("Summary").CheckBoxes("Branch_ChkBox").Visible = False
Set Rng = Sheets("Summary").Range("B9:N37")
Rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
'Sheets("Summary").Branch_ChkBox.Visible = False
'Row1Circle Sheets("Summary").CheckBoxes("Branch_ChkBox").Visible = False
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set olApp = CreateObject("Outlook.Application")
Set Email = olApp.CreateItem(0)
Set wdDoc = Email.GetInspector.WordEditor
'strbody = "See production data for most recent 3 months. "
With Email
.To = Worksheets("Summary").Range("B21").Value
.Subject = "12 Month LO Production Lookback for " & Worksheets("Summary").Range("B21").Value & " (" & Worksheets("Summary").Range("B23").Value & "- " & Worksheets("Summary").Range("B34").Value & ")"
'.HTMLBody = "<BODY style=font-size:12.5pt;font-family:Calibri>" & "</p>" & strbody & RangetoHTML(rng) & Signature
.Display
wdDoc.Range.PasteAndFormat Type:=wdChartPicture
'if need setup inlineshapes hight & width
With wdDoc.Content
'--- paste the range image first, because it overwrites
' everything in the document
.PasteAndFormat Type:=wdChartPicture
.InlineShapes(1).Height = 350
'--- now add our greeting at the start of the email
.InsertBefore "See 12 month production data and current pipeline. " & vbCr & vbCr
'--- finally add our sign off after the image
.InsertAfter vbCr & _
"Thank you" & vbCr & vbCr
End With
.Display
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set Email = Nothing
Set olApp = Nothing
Sheets("Summary").CheckBoxes("Branch_ChkBox").Visible = True
ActiveSheet.Shapes("Row1Circle").Visible = True
ActiveSheet.Shapes("Row2Circle").Visible = True
ActiveSheet.Shapes("Row3Circle").Visible = True
ActiveSheet.Shapes("Row4Circle").Visible = True
ActiveSheet.Shapes("Row5Circle").Visible = True
ActiveSheet.Shapes("Row6Circle").Visible = True
ActiveSheet.Shapes("Row7Circle").Visible = True
ActiveSheet.Shapes("Row8Circle").Visible = True
ActiveSheet.Shapes("Row9Circle").Visible = True
ActiveSheet.Shapes("Row10Circle").Visible = True
ActiveSheet.Shapes("Row11Circle").Visible = True
ActiveSheet.Shapes("Row12Circle").Visible = True
ActiveSheet.Shapes("Apps1Circle").Visible = True
ActiveSheet.Shapes("Apps2Circle").Visible = True
ActiveSheet.Shapes("Apps3Circle").Visible = True
ActiveSheet.Shapes("Apps4Circle").Visible = True
ActiveSheet.Shapes("Apps5Circle").Visible = True
ActiveSheet.Shapes("Apps6Circle").Visible = True
ActiveSheet.Shapes("Apps7Circle").Visible = True
ActiveSheet.Shapes("Apps8Circle").Visible = True
ActiveSheet.Shapes("Apps9Circle").Visible = True
ActiveSheet.Shapes("Apps10Circle").Visible = True
ActiveSheet.Shapes("Apps11Circle").Visible = True
ActiveSheet.Shapes("Apps12Circle").Visible = True
ActiveSheet.Shapes("Fund1Circle").Visible = True
ActiveSheet.Shapes("Fund2Circle").Visible = True
ActiveSheet.Shapes("Fund3Circle").Visible = True
ActiveSheet.Shapes("Fund4Circle").Visible = True
ActiveSheet.Shapes("Fund5Circle").Visible = True
ActiveSheet.Shapes("Fund6Circle").Visible = True
ActiveSheet.Shapes("Fund7Circle").Visible = True
ActiveSheet.Shapes("Fund8Circle").Visible = True
ActiveSheet.Shapes("Fund9Circle").Visible = True
ActiveSheet.Shapes("Fund10Circle").Visible = True
ActiveSheet.Shapes("Fund11Circle").Visible = True
ActiveSheet.Shapes("Fund12Circle").Visible = True
ActiveSheet.Shapes("Fund12Circle").Visible = True
End Sub