[英]Add Outlook Search Folder on shared folder
I'm trying to create a new "Search Folder" in an Outlook shared folder using VBA in Excel.我正在尝试使用 Excel 中的 VBA 在 Outlook 共享文件夹中创建一个新的“搜索文件夹”。
It is failing on the last line, which is the save function.它在最后一行失败,即保存功能。
"Object could not be found".
“找不到对象”。
Sub createfolder()
Dim oApp As Outlook.Application
Dim oSearch As Outlook.Search
Dim oInbox As Outlook.mapifolder
Dim sFolderPath As String
Dim oScope As String
Dim sFilter As String
Set oApp = New Outlook.Application
Set oInbox = oApp.GetNamespace("MAPI").Folders("Fin Reporting").Folders("July")
sFolderPath = oInbox.FolderPath
sScope = "'" & oInbox.FolderPath & "'"
Set oSearch = oApp.AdvancedSearch(sScope)
oSearch.Save ("TestSearch")
End Sub
you did not say where your "fin reporting" folder is located你没有说你的“fin报告”文件夹在哪里
for this example code, i put it in the top folder, so it is on same level as "inbox"对于此示例代码,我将其放在顶部文件夹中,因此它与“收件箱”处于同一级别
top ---
|
fin reporting
| |
| july
|
inbox
|
sent items
|
etc.
try these two.试试这两个。 see which one works, or does not work.
看看哪个有效,或无效。
single-step through the code by pressing F8 key repeatedly重复按 F8 键单步执行代码
try this one in outlook在 Outlook 中试试这个
Sub createfolder_outlook()
Dim oInbox As MAPIFolder
Dim oSearch As Search
Set oInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Fin Reporting").Folders("July")
Set oSearch = Application.AdvancedSearch("'" & oInbox.FolderPath & "'")
oSearch.Save ("TestSearch")
End Sub
then do same in excel然后在excel中做同样的事情
Sub createfolder_excel()
Dim oInbox As Outlook.MAPIFolder
Dim oSearch As Outlook.Search
Set oInbox = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(Outlook.olFolderInbox).Parent.Folders("Fin Reporting").Folders("July")
Set oSearch = Outlook.Application.AdvancedSearch("'" & oInbox.FolderPath & "'")
oSearch.Save ("TestSearch")
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.