用自定义值替换MailEnvelop中的复选框

时间:2019-04-15 13:57:41

标签: vba ms-word

我需要将文档作为电子邮件正文发送。该文档包含几个{ FORMCHECKBOX }字段,可以选择是否选择。现在,无论何时我实际发送电子邮件,都根本不包括这些复选框。由于这个问题,我很想根据选择将复选框替换为“是”或“否”。

我找到了这段代码,以替换所有复选框,但它并不适合实际选择:

Sub ChkBxClr()
    Dim i As Long, Rng As Range
    With ActiveDocument
        For i = .FormFields.Count To 1 Step -1
            With .FormFields(i)
                If .Type = wdFieldFormCheckBox Then
                    Set Rng = .Range
                    .Delete
                    Rng.Text = "[__]"
                End If
            End With
        Next
        Set Rng = Nothing
    End With
End Sub

此代码还更改了整个文档,而不仅仅是电子邮件正文,我想防止这种情况。

整体代码:

Sub SendEmail()

    Dim Subject As String
    Dim From As String

    On Error Resume Next

    Selection.GoTo What:=wdGoToBookmark, Name:="From"
    From = Selection.Text

    Subject = "Title"

    Call ChkBxClr

    ActiveWindow.EnvelopeVisible = True
    With ActiveDocument.MailEnvelope.Item
        .To = "<some mail address>"
        .Subject = Subject
        .Send
    End With

End Sub

Sub ChkBxClr()
    Dim i As Long, Rng As Range
    With ActiveDocument
        For i = .FormFields.Count To 1 Step -1
            With .FormFields(i)
                If .Type = wdFieldFormCheckBox Then
                    Set Rng = .Range
                    .Delete
                    Rng.Text = "[__]"
                End If
            End With
        Next
        Set Rng = Nothing
    End With
End Sub

问题是,如何根据选择内容显示电子邮件正文中的复选框用文本替换复选框(最好仅在邮件正文中)?

0 个答案:

没有答案