简体   繁体   中英

Forward email with a table in the body

I'm really new to using vba in Outlook.

I was wondering if there is a way to write a script which can do the following When run, it can forward the email to a particular address and put a blank table in the body with 4 rows and 4 columns

any help will be much appreciated Thanks

Work with Tables.Add Method (Word) which Returns a Table object that represents a new, blank table added to a document.

Make sure the Email is HTML format

Syntax

expression .Add(Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)

Your Outlook Code Example would be

Option Explicit
Public Sub Example()
    Dim Item As Outlook.mailitem
    Dim Forward As Outlook.mailitem
    Dim Recip As Recipient
    Dim Inspector As Outlook.Inspector
    Dim wdDoc As Word.Document
    Dim Selection As Word.Selection
    
'   // Select the Item you would like to forward    
    Set Item = Application.ActiveExplorer.Selection.Item(1)
    Set Forward = Item.Forward
    Set Recip = Forward.Recipients.Add("0m3r@Email.com")
        Recip.Type = olTo
        Forward.Display
        
    Set Inspector = Application.ActiveInspector()
    Set wdDoc = Inspector.WordEditor
    Set Selection = wdDoc.Application.Selection
    
        Selection.Tables.Add Range:=Selection.Range, _
                             NumRows:=4, NumColumns:=4, _
                             DefaultTableBehavior:=wdWord9TableBehavior, _
                             AutoFitBehavior:=wdAutoFitFixed
    
    
'        // Uncomment to send
'        Forward.Sent
        
    Set Inspector = Nothing
    Set wdDoc = Nothing
    Set Selection = Nothing
End Sub

Email Body Example

在此处输入图片说明


Remember to add reference to word xx object library

1. From the Tools menu, choose References to display the References dialog box.

2. The References dialog box shows all object libraries registered with the operating system. Scroll through the list for the application whose object library you want to reference. If the application isn't listed, you can use the Browse button to search for object libraries ( .olb and .tlb) or executable files ( .exe and .dll on Windows). References whose check boxes are checked are used by your project; those that aren't checked are not used, but can be added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM