Outlook VBA查找回复来源的项目的属性 [英] outlook vba find properties of the item the reply is originated from

查看:132
本文介绍了Outlook VBA查找回复来源的项目的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的电子邮件中有用户定义的属性.我希望在对新项目进行答复的情况下将它们复制(从一项答复中发出).

I have user-defined properties in my emails. I would like them to be copied in case of an reply to the new item (from the one, the reply was originated from).

这不是问题,但是下面的代码是从 https://docs.microsoft. com/de-de/office/vba/api/outlook.mailitem.reply%28even%29 运行Initialize_Handler时出现"VBA错误91:未设置对象变量"的信息.

This would not be the problem, but with the code below copied from https://docs.microsoft.com/de-de/office/vba/api/outlook.mailitem.reply%28even%29 I get "VBA Error 91: Object Variable not set" when running Initialize_Handler

Public WithEvents myItem As MailItem 

Sub Initialize_Handler() 
  Set myItem = Application.ActiveInspector.CurrentItem 
End Sub 

Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean) 
  ...code for copying user-defined properties...
End Sub

什么原因导致此错误?如果"ThisOutlookSession"中仅包含此代码,甚至会出现.

What causes this error? It even comes if "ThisOutlookSession" has only this code in it.

我是否正在寻找从原始电子邮件项目获取值/属性的正确方法?

And am I looking the right way for getting values/properties from the original-email-item?

谢谢! 最高

推荐答案

在另一页上,我找到了可行的解决方案.这里是完整的(适应的)代码:

on another page i found a solution that works. Here the full (adapted) code:

Option Explicit
Public WithEvents objInspectors As Outlook.Inspectors
Public WithEvents objExplorer As Outlook.Explorer
Public WithEvents olitem As Outlook.mailitem

Private Sub Application_Startup()
 Dim myRecipient As Outlook.Recipient
 Dim folder As Outlook.MAPIFolder

 Set objInspectors = Outlook.Inspectors
 Set objExplorer = Outlook.Application.ActiveExplorer
End Sub
Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    Dim olitem As Object
    Set olitem = Inspector.CurrentItem
    If TypeName(olitem) = "MailItem" Then Set olitem = olitem
End Sub

Private Sub olitem_Forward(ByVal Forward As Object, Cancel As Boolean)
 Call kennzeichn_auto(olitem, Forward)
End Sub
Private Sub olitem_Reply(ByVal response As Object, Cancel As Boolean)
 Call kennzeichn_auto(olitem, response)
End Sub
Private Sub olitem_ReplyAll(ByVal response As Object, Cancel As Boolean)
 Call kennzeichn_auto(olitem, response)
End Sub
Sub kennzeichn_auto(olitem As mailitem, response As mailitem)
 Call AddUserProperty(response, "Kunde", wert_property(olitem, "Kunde"))
 Call AddUserProperty(response, "Bearbeiter", wert_property(olitem, "Bearbeiter"))
 Call AddUserProperty(response, "KundeNo", wert_property(olitem, "KundeNo"))
End Sub

这篇关于Outlook VBA查找回复来源的项目的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆