olFolder.Folders.Add 函数有更新的代码吗?
Is there updated code for olFolder.Folders.Add function?
我这里有下面的代码,可以在 Outlook 中创建一个新文件夹。
此代码有效,但系统已使用 Microsoft proplus 进行了更新。
现在发生错误。
Sub Create_Folder()
Dim olApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem
Dim wb As Workbook
Dim ws As Worksheet
Dim cell As Range
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Data")
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Folders.Add ("Saved Data") ' run time error cannot create folder occures here
Set olFolder = olFolder.Folders("Saved Data")
具体错误是什么?如果该文件夹已经存在,您将 收到错误消息。您需要先测试文件夹是否存在:
on error resume next
err.Clear
set subFolder = olFolder.Folders("NDR")
if err.Number <> 0 Then
set subFolder = olFolder.Folders.Add("NDR")
End If
我这里有下面的代码,可以在 Outlook 中创建一个新文件夹。 此代码有效,但系统已使用 Microsoft proplus 进行了更新。 现在发生错误。
Sub Create_Folder()
Dim olApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem
Dim wb As Workbook
Dim ws As Worksheet
Dim cell As Range
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Data")
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Folders.Add ("Saved Data") ' run time error cannot create folder occures here
Set olFolder = olFolder.Folders("Saved Data")
具体错误是什么?如果该文件夹已经存在,您将 收到错误消息。您需要先测试文件夹是否存在:
on error resume next
err.Clear
set subFolder = olFolder.Folders("NDR")
if err.Number <> 0 Then
set subFolder = olFolder.Folders.Add("NDR")
End If