使用 VBA 将内容控件值转换为字符串

Convert Content Control value to String using VBA

我正在开发一个脚本来格式化 Outlook 模板并通过单击按钮发送它。 主要目标是在 After/Before 间距上使用单行间距和 0pt,并将我模板上的所有内容控件(例如组合框)转换为 Text/String.

Sub FormatAndSend()
    Dim CurrentMessage As Outlook.MailItem

    If TypeName(Application.ActiveWindow) = "Inspector" Then
        Set CurrentMessage = Application.ActiveWindow.CurrentItem

        If CurrentMessage.To = "" Then
            If CurrentMessage.CC = "" Then
                If CurrentMessage.BCC = "" Then Exit Sub
            End If
        End If

        CurrentMessage.HTMLBody = Replace(CurrentMessage.HTMLBody, vbCr, vbCrLf)
        'Workaround to Remove Line Spacing (not working)
        '&
        'Convert Content Control selected values to String ...

        CurrentMessage.Send

        Set CurrentMessage = Nothing
    End If
End Sub

有没有更简单的方法来格式化现有模板?我已经尝试了几件事,例如用 ASCII 字符替换,HTML 元素,关键字,...

此外,是否可以将内容控件选择的值转换为普通文本?

我设法通过使用正则表达式删除 OOXML 元素并更改 CSS 属性来解决我的问题。

Dim regX As Object
Set regX = CreateObject("VBScript.RegExp")

regX.Global = True
regX.MultiLine = True
regX.IgnoreCase = False
regX.Pattern = "<\/?w:[A-z].*?>"

CurrentMessage.HTMLBody = regX.Replace(CurrentMessage.HTMLBody, "")
CurrentMessage.HTMLBody = Replace(CurrentMessage.HTMLBody, "<p class=MsoNormal>", _
                            & "<p class=MsoNormal style='margin:0;line-height:0;'>")
Set regX = Nothing