我正在尝试创建一个模板,我可以让VBA提示我更改主题中的项目。我有一个模板电子邮件,主题行应该是Project / GC / Client,在模板中我写的是#0#/#1#。
我在下面,但它的错误。
Private Sub m_Inspector_Activate()
Dim Item As MailItem
Dim Value As String
If TypeOf m_Inspector.CurrentItem Is MailItem Then
Set mail = m_Inspector.CurrentItem
If mail.Subject = "subject" Then
Value = InputBox("Project")
mail.Subject = Replace(mail.Subject, "#0#", Value)
Value = InputBox("GC/Client")
mail.Subject = Replace(mail.Subject, "#1#", Value)
End If
End If
End Sub
此代码用于Outlook中的模板按钮。即它正在启动的模板文件包含#0#/#1#的主题行。理想情况下,在模板启动后,宏会提示用户使用适当的主题更新这两个字段。
Sub CommandButton1_Click()
Set MyItem = Application.CreateItemFromTemplate _
("V:\All Folders\Templates\Freebie.oft")
MyItem.Display
End Sub
答案 0 :(得分:0)
如果您真正想要做的就是打开模板并替换主题行中的文字,这可能对您有用:
Sub CommandButton1_Click()
Call OpenTemplate
End Sub
Sub OpenTemplate()
Dim OutMail As Outlook.MailItem
Set OutMail = Application.CreateItemFromTemplate("V:\All Folders\Templates\Freebie.oft")
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = Replace(.Subject, "#0#", InputBox("Project"))
.Subject = Replace(.Subject, "#1#", InputBox("GC/Client"))
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
如果我们可以避免使用Inspector,那么这就简单了