大家晚上好
我有一个 Excel 宏,我正在尝试使其工作并稍微适应。我需要解决 3 个问题:
我的代码抛出编译错误:“End if without block if”。我是初学者,不知道这意味着什么?
我需要修改我的代码,以便它也扫描电子邮件的自动签名,但不知道该怎么做。
我想修改代码,以便它从主题字段、电子邮件正文和括号中包含的自动签名中提取任何数据,并将其发送到 Excel 中的各个行。但是,我想使用标记 R1、R2、R3、R4、R5、R6,以便标记 R1 的括号中的数据被吐出到我的 Excel s/sheet 的第 1 行,标记为 R2 的括号中的数据被吐出到第 2 行等等。见下图。有人建议我可以使用 FIND 和 MID 函数,但我的知识还不够强大,无法编写此代码。
如果有人可以帮助我,我将不胜感激:)
我的代码:
Sub GetFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("NoV")
i = 1
For Each OutlookMail In Folder.Items
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
在下面的代码中:
For Each OutlookMail In Folder.Items
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
End If
Next OutlookMail
代码中没有
If
运算符,因此不需要 End If
:
For Each OutlookMail In Folder.Items
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
Next OutlookMail