문제

I'm trying to cause a new Outlook item to be created in a specific store when the user saves it. Normally if there are multiple accounts, when you create a new item (e.g. press Ctrl+Shift+K for a task), the new item is created in the default folder for the active account.

I tried intercepting the inspector for the new item and moving it, but it had no effect. Here is the gist of the code (checking to avoid non-new items is omitted):

Dim WithEvents inspectors As Outlook.inspectors

Private Sub Application_Startup()
    Set inspectors = Application.inspectors
End Sub

Private Sub inspectors_NewInspector(ByVal Inspector As Inspector)
    Dim item As Object
    Set item = Inspector.CurrentItem
    If item Is Nothing Then Exit Sub
    If item.Class <> olTask Then Exit Sub
    item.Move Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks)
End Sub

Unfortunately, the Move method has no effect. Any ideas?

도움이 되었습니까?

해결책

You can't move unsaved items. How are you creating the item?

Use the Items.Add method to add an item (i.e. create it) in a specific folder. If you are using the CreateItem Method, it will always be created in the default folder for that item type.

Instead of trying to use the existing functionality to try and create the task (which I'm not sure is possible or easy) I think you are better off creating a macro that creates the task in the folder you want, then add the macro to a toolbar button. Or you could try and save the item first, then move it. Note that your current code moves the item to the default Tasks folder.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top