VBA Outlook表

问题描述 投票:0回答:1

我有一个Outlook宏,可以在Outlook会议中插入一个表格。然而,我想在表格前添加一个文本,我无法做到。请帮助

以下是我的宏代码

Sub InsertText()

    Const sText As String = "Enter this text at the cursor"

   ' On Error GoTo ErrHandler

    If TypeName(ActiveWindow) = "Inspector" Then

            If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then

              With ActiveInspector.WordEditor.Application.ActiveDocument

                .Tables.Add Range:=.Range, NumRows:=3, NumColumns:= _
                2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
                wdAutoFitFixed
                With .Tables(1)
                    If .Style <> "Table Grid" Then
                     .Style = "Table Grid"
                    End If
                    .ApplyStyleHeadingRows = True
                    .ApplyStyleLastRow = False
                    .ApplyStyleFirstColumn = True
                    .ApplyStyleLastColumn = False
                    .ApplyStyleRowBands = True
                    .ApplyStyleColumnBands = False
                    .Cell(1, 1).Range.Text = "Meeting purpose"
                    .Cell(1, 2).Range.Text = "The purpose of this meeting to discuss business future"
                    .Cell(2, 1).Range.Text = "Meeting Participants"
                    .Cell(3, 1).Range.Text = "Participant task for the meeting"
                 End With
        End With

             End If
    End If


    Exit Sub
ErrHandler:
    MsgBox "Some Error"
End Sub
vba outlook word
1个回答
0
投票

你可以自由使用以下代码。

Dim rng as Word.Range

With ActiveInspector.WordEditor
                Set rng = .Range(0, 0);
                rng.Text = "New Text"

                .Tables.Add Range:=.Range, NumRows:=3, NumColumns:= _
                2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
                wdAutoFitFixed
                With .Tables(1)
                    If .Style <> "Table Grid" Then
                     .Style = "Table Grid"
                    End If
                    .ApplyStyleHeadingRows = True
                    .ApplyStyleLastRow = False
                    .ApplyStyleFirstColumn = True
                    .ApplyStyleLastColumn = False
                    .ApplyStyleRowBands = True
                    .ApplyStyleColumnBands = False
                    .Cell(1, 1).Range.Text = "Meeting purpose"
                    .Cell(1, 2).Range.Text = "The purpose of this meeting to discuss business future"
                    .Cell(2, 1).Range.Text = "Meeting Participants"
                    .Cell(3, 1).Range.Text = "Participant task for the meeting"
                 End With
        End With
© www.soinside.com 2019 - 2024. All rights reserved.