[英]Object Required VBA Outlook
I'm not sure what it doesn't like about my code here, I'm experienced in .NET, but VBA is new to me.我不确定我的代码不喜欢这里的什么,我在 .NET 方面有经验,但 VBA 对我来说是新的。 I know when called functions not to do myFunction('args') and do myFunction args instead, but I don't have that issue here.我知道何时调用函数不执行 myFunction('args') 而是执行 myFunction args,但我在这里没有这个问题。 Any help is appreciated.任何帮助表示赞赏。 THanks!谢谢!
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
You try to assign object reference to data type .您尝试将对象引用分配给数据类型。 String is a data type in VBA and not an object.字符串是 VBA 中的一种数据类型,而不是对象。 The keyword Set
is used with object.关键字Set
与 object 一起使用。 Remove this keyword when it's data type or you will get an error.当它是数据类型时删除这个关键字,否则你会得到一个错误。
Dim body As String
Dim subject As String
Set body = omailitem.body
Set subject = omailitem.subject
Dim pos As Integer
Set pos = 0
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.