Log in

View Full Version : Forward an outlook email with excel VBA



Yoan_Geneva
11-13-2018, 06:00 AM
Dear members,

I have the following the code to forward an email outlook to another email adresses.


sub Forward_Email

Dim myItem as outlook.mailitem
Dim oloutmail as outlook.mailitem
Dim myinspector as outlook.inspector
Dim wdDoc as word.document
Dim wdRange as word.range
Dim outapp as object

Set Outapp=outlookApp

Set myitem = outapp.activeExplorer.selection.item(1)
set myinspector=myitem.GetInspector
set wdDoc=myInspector.WordEditor

There is a bug with the following code:
set wdDoc=myInspector.WordEditor --> "Application-defined or object-defined error"

Anyone can help with this error.

(I didn't put the full code as I can't copy paste my code)

Thanks

Kenneth Hobs
11-20-2018, 08:31 AM
Welcome to the forum!

Maybe set the word object or Display?

Sub EmbedClipboardAndAppendClipboardInBody()
Dim ws As Worksheet, r As Range, b As Range
'Tools > References > Microsoft Outlook xx.0 Object Library
Dim olApp As Outlook.Application, olMail As Outlook.MailItem
'Tools > References > Microsoft Word xx.0 Object Library
Dim Word As Document, wr As Word.Range

Set ws = Worksheets("Renewal Dates")
Set r = ws.Range("A1:G1")

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.Importance = olImportanceNormal
.To = "ken@gmail.com"
.Subject = "31 Day Reminder"

.GetInspector.Display
Set Word = .GetInspector.WordEditor

r.Copy
Word.Range(0, 0).Paste
r.Offset(2).Copy
Set wr = Word.Content
wr.Collapse Direction:=wdCollapseEnd
wr.Paste 'Paste at end
Application.CutCopyMode = False

'https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.deferreddeliverytime.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
.DeferredDeliveryTime = Now + TimeValue("00:10:00")
.Display
'.Send
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub