我試圖執行以下操作: 我有收件箱中的電子郵件列表(名爲「A_Classer」) 我需要運行代碼將這些電子郵件並將它們放在另一個文件夾中。該目標文件夾將根據郵件的主題而有所不同。 我需要在Excel中執行此操作,因爲目標文件將根據我的Excel工作簿中的信息而有所不同。Excel VBA:在不使用GetNamespace(「MAPI」)的情況下將公用文件夾中的Outlook電子郵件移動
所以我的問題是,我正在使用Windows 32位系統。所以從我讀過的東西看來,它不支持GetNamespace(「Mapi」)方法。因爲當我運行它時,我在GetNamespace(「Mapi」)行上得到一個「錯誤438」
如果目標文件駐留在我的收件箱中,我可以做到,但我需要將電子郵件移動到公用文件夾。
所以在這裏我與我的代碼到目前爲止。如果有人能幫助我通過438這個有用的錯誤。
Sub move_to_public_folder()
Dim msg As Outlook.MailItem
Dim olFolder As Outlook.Folder 'public folder where I want the email to be moved
Dim sourceFolder As Outlook.Folder 'current folder of the emails that are to be moved
Dim OlApp As Object
Dim myNamespace As Outlook.Namespace
Dim myRecipient As Outlook.Recipient
Set OlApp = CreateObject("Outlook.Application") 'ouverture du outlook
Set myNamespace = Application.GetNamespace("MAPI") 'WHERE I GET THE 438 ERROR
Set myRecipient = myNamespace.CreateRecipient("guillaume.hebert")
Set olFolder = Session.GetSharedDefaultFolder(myRecipient, olPublicFoldersAllPublicFolders)
Set olFolder = olFolder.Folders("\Q12")
Set sourceFolder = Session.GetDefaultFolder(sourceFolderInbox)
Set sourceFolder = sourceFolder.Folders("A_Classer")
If sourceFolder Is Nothing Then Exit Sub
I = sourceFolder.Items.Count
nbre_op = I 'détermine combien de courriel dans le répertoire
I = 1
While I <= nbre_op
Set msg = olFolder.Items(1)
msg.Move olFolder
I = I + 1
Wend
Set OlApp = Nothing
末次
非常感謝你提前!
Tx這麼多xmojmr!像魅力一樣工作。現在我有另一個問題是,我不知道如何設置olFolder,如果它是公用文件夾。我會在此發佈另一個問題。如果你可以看看它,但現在無論如何。 – excelguigui11 2014-12-06 17:05:08