TaigaMaki
TaigaMaki

Reputation: 3

How to import local .msg file to Outlook folder using VBA?

I'm trying to copy a local .msg file (like C:\temp\DUMMY.msg) to an Outlook folder (like AAA).

I can get the entryID of AAA folder by using MAPI.

I found Import .msg file to outlook custom folder using c#.

I have imported library written in below.

I assigned destination Outlook folder obj to MyFolder.

If argStrEntryID = "" Then
    Set MyFolder = oApp.Session.GetDefaultFolder(olFolderInbox)
Else
    Set MyFolder = oApp.Session.GetFolderFromID(argStrEntryID)
End If

How do I move the local .msg file to an Outlook folder?

Upvotes: 0

Views: 1735

Answers (2)

TaigaMaki
TaigaMaki

Reputation: 3

as Dmitry mentioned, I used Namespace.OpensharedItem and it worked.


Dim Filename As String
Filename = "C:\temp\DUMMY.msg"

Dim DestOlDirID As String
DesOlDirID = "(entry id value)"

Dim oApp
Set oApp = CreateObject("Outlook.Application")

'Get Namespace object
Dim oNamespace As Namespace
Set oNamespace = oApp.GetNamespace("MAPI")

'assign outlook folder by entry ID
Dim oFolder As Folder
Set oFolder = oApp.Session.GetFolderFromID(DesOlDirID)

Dim oItem As Object
Set oItem = oNamespace.OpenSharedItem(Filename)

'actually this move method did not delete original .msg local file. it works like copy.
oItem.Move oFolder

Set oItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

You can use Namespace.OpenSharedItem specifying the MSG file fully qualified file name and then copy (MailItem.Copy) or move it (MailItem.Move).

Upvotes: 0

Related Questions