作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 Outlook 中保存所选项目。使用下面的代码,我可以保存该项目,但它只保存第一个项目而不是所选项目。
我需要更改什么才能保存所选项目?
Dim oOlApp As Object, objNmSpc As Object, ofldr As Object
Dim myCopiedItem As Outlook.MailItem
Dim myNewFolder As String
Set oOlApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set oOlApp = CreateObject("Outlook.Application")
End If
Err.Clear
Set objNmSpc = oOlApp.GetNamespace("MAPI")
Set ofldr = objNmSpc.PickFolder
If Not ofldr Is Nothing Then MsgBox ofldr
Dim oItem As Object
For Each oItem In ofldr.Items
If oOlApp.ActiveExplorer.Selection.Item(1) = True Then
oItem.SaveAs Sheet1.Range("V5").Value & oItem.Subject & ".msg", olMSG
match.Offset(, 7).Value = oItem.SenderName & "-" & oItem.Subject & "-" & oItem.ReceivedTime
match.Offset(, 8).Value = VBA.Environ("Username") & "- " & VBA.Now
Exit Sub
End If
Next oItem
最佳答案
如果没有错误,下面的行将不会运行
If oOlApp.ActiveExplorer.Selection.Item(1) = True Then
此外,您正在调用 Exit sub
,这意味着只能处理一个项目。
绝对没有理由遍历文件夹中的所有项目。将循环更改为以下内容
For Each oItem In oOlApp.ActiveExplorer.Selection
oItem.SaveAs Sheet1.Range("V5").Value & oItem.Subject & ".msg", olMSG
match.Offset(, 7).Value = oItem.SenderName & "-" & oItem.Subject & "-" & oItem.ReceivedTime
match.Offset(, 8).Value = VBA.Environ("Username") & "- " & VBA.Now
Next oItem
关于vba - 如何在 Outlook VBA 中保存选定的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45485283/
我是一名优秀的程序员,十分优秀!