我正在开发一个脚本来格式化Outlook模板并通过单击按钮发送它。 主要目标是在间距之前/之前使用单行间距和0pt,并将模板上的所有内容控件(如组合框)转换为文本/字符串。
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元素,关键字......
此外,是否可以将内容控制选定值转换为普通文本?
答案 0 :(得分:0)
我设法通过使用正则表达式删除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