vba - 对象所需的 VBA Outlook

标签 vba outlook

我不确定我的代码有什么不喜欢的地方,我在 .NET 方面经验丰富,但 VBA 对我来说是个新手。我知道调用函数时不执行 myFunction('args') 而是执行 myFunction args,但我这里没有这个问题。任何帮助表示赞赏。谢谢!

Public Sub LogMeIn()
Dim item As Outlook.MailItem
Dim body As String
Dim subject As String
Dim oFld As Outlook.Folder
Dim oNS As Outlook.NameSpace
Dim oMails As Outlook.items
Dim oProp As Outlook.PropertyPage
Dim mySelection As Word.Selection
Dim strItem As String
Dim omailitem As Variant

Set oNS = Application.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderInbox)
Set oMails = oFld.items

For Each omailitem In oMails
Set body = omailitem.body
Set subject = omailitem.subject
Dim pos As Integer
Set pos = 0
Dim copyText As String
If InStr(omailitem.subject, "Your LogMeIn Security Code:") > 0 Then
Set copystr = Mid(omailitem.body, pos + 28, 9)
Dim dataToSave As New DataObject
dataToSave.SetText copystr
dataToSave.putinclipboard

'MsgBox ("subject true")
End If

'MsgBox ("subject true")
'If omailitem.subject.Find("Your LogMeIn Security Code:") Then
'MsgBox ("subject true")
'End If

Next

End Sub

Private Sub Application_NewMail()
Call LogMeIn
End Sub

最佳答案

您尝试将对象 引用分配给数据类型String 是 VBA 中的一种数据类型,而不是对象。关键字 Set 与对象一起使用。当它是数据类型时删除这个关键字,否则你会得到一个错误。

Dim body As String
Dim subject As String

Set body = omailitem.body
Set subject = omailitem.subject

Dim pos As Integer
Set pos = 0

[...]

关于vba - 对象所需的 VBA Outlook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16419727/

相关文章:

arrays - 打乱数组,以便没有项目保留在同一位置

ms-access - 我如何解决 MS Access 的 2GB 数据库限制(用于显示图像)?

excel - 在 VBA 中循环使用具有相似名称结构的工作表

c# - Outlook ItemAdd 事件针对新日历项目触发两次

excel - 切换到 64 位 Excel 后如何修复 VBA "type mismatch"错误

java - 将 Android 应用程序连接到 PC

android - 以编程方式在android中发送带附件的电子邮件

ios - 我只想打开 MS Outlook 应用程序并在 iOS 上使用 URL Scheme 查看 mailto 屏幕

html - 如何从 Outlook 2010/2013 中的 html 电子邮件模板回复中删除背景颜色

Excel:连接列中的最后一个非空单元格