Consulting

Results 1 to 2 of 2

Thread: Forward an outlook email with excel VBA

  1. #1

    Forward an outlook email with excel VBA

    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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •