Vba 将MailItem传递给函数
我正在搜索如何通过函数传递邮件项 例如:我想调用一个函数来提取MailItem的主题Vba 将MailItem传递给函数,vba,outlook,Vba,Outlook,我正在搜索如何通过函数传递邮件项 例如:我想调用一个函数来提取MailItem的主题 Function testpassing(myMail As Outlook.MailItem) As Actions MsgBox (myMail.Subject) End Function Sub passing() Dim myItem As Outlook.MailItem Set myItem = Application.GetNamespace("MAPI").GetDef
Function testpassing(myMail As Outlook.MailItem) As Actions
MsgBox (myMail.Subject)
End Function
Sub passing()
Dim myItem As Outlook.MailItem
Set myItem = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items(1)
MsgBox (myItem.Subject) '<~ Work correctly
testpassing (Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items(1)) '<~ Run-time error 438 Object doesn't support this property or method
testpassing (myItem) '<~ Run-time error 438 Object doesn't support this property or method
End Sub
函数testpassing(myMail作为Outlook.MailItem)作为操作
MsgBox(myMail.Subject)
端函数
子传递()
将myItem设置为Outlook.MailItem
设置myItem=Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Items(1)
MsgBox(myItem.Subject)称它为testpassing myItem
和testpassing Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderIn方框)。项目(1)
还可以查看
您可以通过引用或值将参数传递给过程(函数或子过程)
一如既往地快乐编码:-)文件夹可能包含不同的项目类型。我建议首先检查项目类型(或消息类):
有关更多信息,请参阅 请在调用testpassing
的地方显示代码,您的函数实际上没有返回任何内容-这可能也是问题的一部分。我建议您将整个宏模块发布在此处,缺少太多上下文来诊断问题。整个宏太乱了,但我会缩短它,然后在这里发布。@0m3r哇!你是传奇人物!
If Item(1).Class = OlObjectClass.olMail Then
'
End If