【问题标题】:Select Signature before sending email / Outlook VBA在发送电子邮件/Outlook VBA 之前选择签名
【发布时间】:2021-12-21 06:41:36
【问题描述】:

我需要有关 vba 代码的帮助。我需要一个提示框,我可以在其中选择三个签名中的一个,然后再发送电子邮件。当然我知道我可以在写电子邮件时手动选择它,但是我们的团队使用客户的个人数据,它必须提醒选择一个好的。我创建了一个简单的脚本,它显示提示信息“你选择了正确的签名吗”,但这还不够。以前从未在 Outlook 中使用过 VBA,所以更难。

【问题讨论】:

  • 请编辑您的问题并向我们展示您到目前为止所做的工作,并解释您的代码的哪些部分不起作用。

标签: vba outlook


【解决方案1】:

你需要做如下:

.SendUsingAccount = OutApp.Session.Accounts.Item(1)

这个问题已经有答案了there

归功于Siddharth Rout

【讨论】:

  • 嗨!感谢您的回答,但恐怕这不是我想要的(或者我不知道如何使用它)。您链接的主题是关于 excel,您可以在其中将宏链接到按钮。我只想在每次单击“发送”或创建消息并选择 X 签名之一时调用提示框。
  • @mszna 要在 VBA 中显示提示弓,只需执行 Application.Input()
  • 我想出了如何部分实现你在链接中给我的代码,但是当我在 Outlook 中单击“新消息”时不知道如何运行用户窗体。 “新消息”事件后是否有打开用户表单的选项?
  • @mszna 你解决了吗?
【解决方案2】:

我决定使用用户表单。我的代码工作了一段时间,但我改变了一些东西,现在它不起作用,我被卡住了。

ThisOutlookSession:

Public WithEvents myOlInspectors As Outlook.Inspectors

Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    
    Dim stopka As String
    Dim msg As Outlook.MailItem
    If Inspector.CurrentItem.Class = olMail Then
        Set msg = Inspector.CurrentItem
        If msg.Size = 0 Then
           UserForm2.Show
                 
    Select Case lstNum
    Case -1
         stopka = ""
    Case 0
         stopka = "Subject1"
    Case 1
         stopka = "Subject2"
    Case 2
         stopka = "Subject3"
    End Select
          
End If
End If

Subject1 = "<b><font face=""Artifakt Element"" size=""3"" color=""#003366"">blah blah</font></b><br>" _
    & " <b> <font size=""2"" color=""black""> Blah </b> </font> <br>" _
    & " <font size=""2""> Phone: +99 999 999 999 / Mobile: +99 999 999 999 / Mail : <a href=""mailto:blahblah@blah.com""> blah blah </a> </font> <br>" _
    & " <font size=""2""> <b> BLAH-Blah blah blah </b> Warsaw, xxxxxx 32 </font> <br>" _
    & " <br>" _
    & " <font size=""2""> <a href=""www.google.com""> www.google.com </a> / <a href=""www.google.com""> BLAH</a> </font> <br>" _
    & " <font size=""1""> blah blah blah blah blah</font>"
    
With OMail
    .HTMLBody = Subject1 & .HTMLBody
    .Display
Set OMail = Nothing
End With

End Sub

用户窗体2

Private Sub UserForm_Initialize()
  
  With ComboBox1
    .AddItem "Subject1"
    .AddItem "Subject2"
    .AddItem "Subject3"
  End With
End Sub


Private Sub btnOK_Click()
    lstNum = ComboBox1.ListIndex
    Unload Me
End Sub

模块2

Public Sub ChooseTemplate()

Subject1 = "<b><font face=""Artifakt Element"" size=""3"" color=""#003366"">blah blah</font></b><br>" _
        & " <b> <font size=""2"" color=""black""> Blah </b> </font> <br>" _
        & " <font size=""2""> Phone: +99 999 999 999 / Mobile: +99 999 999 999 / Mail : <a href=""mailto:blahblah@blah.com""> blah blah </a> </font> <br>" _
        & " <font size=""2""> <b> BLAH-Blah blah blah </b> Warsaw, xxxxxx 32 </font> <br>" _
        & " <br>" _
        & " <font size=""2""> <a href=""www.google.com""> www.google.com </a> / <a href=""www.google.com""> BLAH</a> </font> <br>" _
        & " <font size=""1""> blah blah blah blah blah</font>"

Dim OMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem

'If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
' Set oContact = ActiveExplorer.Selection.Item(1)

Dim msg As Outlook.MailItem
    If Inspector.CurrentItem.Class = olMail Then
        Set msg = Inspector.CurrentItem
        If msg.Size = 0 Then

Dim strTemplate As String
 Set OMail = Application.CreateItem(olMailItem)
  UserForm1.Show
  
  

    Select Case lstNum
    Case -1
         OMail.Subject = ""
    Case 0
         OMail.Subject = "Subject_1"
    Case 1
         OMail.Subject = "Subject_2"
    Case 2
         OMail.Subject = "Subject_3"
    End Select
End If
With OMail
  .To = oContact.Email1Address
  .ReadReceiptRequested = True
  .Subject = "Test Makro"
  .Body = "Hi " & oContact.FirstName & "," & vbCrLf & vbCrLf & OMail.Body
  .Display
End With
  End If
Set OMail = Nothing


End Sub

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2022-08-10
  • 1970-01-01
  • 2018-04-27
  • 2022-07-11
  • 2013-08-01
  • 1970-01-01
  • 2015-05-03
  • 2011-09-28
  • 1970-01-01
相关资源
最近更新 更多