2016-01-19 62 views
0

我編寫了一個VBA腳本,目前它只能在Outlook中打開的第一個收件箱上運行。更改Outlook收件箱VBA代碼正在運行

如何指定它在哪個收件箱上運行?即另一個帳戶的收件箱。

我假設某處這裏 -

Sub MoveAgedMail() 

Dim objOutlook As Outlook.Application 
Dim objNamespace As Outlook.NameSpace 
Dim objSourceFolder As Outlook.MAPIFolder 
Dim objDestFolder As Outlook.MAPIFolder 
Dim objVariant As Variant 
Dim lngMovedItems As Long 
Dim intCount As Integer 
Dim intDateDiff As Integer 
Dim strDestFolder As String 
+2

此代碼聲明瞭一堆的變數,但*無助* .... –

+0

[獲取參考的可能的複製到額外的收件箱](http://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton

+0

變化的解釋和方法。 http://stackoverflow.com/questions/28310088/using-microsoft-access-need-to-pull-attachments-from-outlook-emails-of-a-differ和http://stackoverflow.com/questions/26274516/ vba-get-email-from-non-default-inbox – niton

回答

1

即,另一帳戶的收件箱。

假設你在談論的共享收件箱

VBA示例代碼將

Option Explicit 
Sub OpenShareInbox() 
    Dim olNameSpace As Outlook.NameSpace 
    Dim olRec As Outlook.Recipient 
    Dim olFolder As Outlook.Folder 

    Set olNameSpace = Application.GetNamespace("MAPI") 
    Set olRec = olNameSpace.CreateRecipient("[email protected]") '// Owner's email address 
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox) 

    MsgBox olRec.Name '// Owner Name 

    olFolder.Display '// Open Inbox 
End Sub 

編輯:

下面是另一個例子 - 打開即時窗口和打印主題行

Option Explicit 
Sub OpenShareInbox() 
    Dim olNameSpace As Outlook.NameSpace 
    Dim olRec As Outlook.Recipient 
    Dim olFolder As Outlook.Folder 

    Dim olItem As Outlook.MailItem 

    Set olNameSpace = Application.GetNamespace("MAPI") 
    Set olRec = olNameSpace.CreateRecipient("[email protected]") '// Owner's email address 
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox) '// Inbox 


    For Each olItem In olFolder.Items 
     Debug.Print olItem.Subject 
    Next 

End Sub 
與主題行「報告」

For Each olItem In olFolder.Items 
    If olFolder.DefaultItemType = olMailItem Then 
     If olItem.Class = olMail Then 
      If olItem.Subject = "Report" Then 
       Set olItem = olItem.Forward 
       olItem.Subject = "APPENDED SUBJECT - " + olItem.Subject + "" 
       olItem.Recipients.Add "Om3r <[email protected]>" 
       olItem.Display 
    '   olItem.Send 
      End If 
     End If 
    End If 
Next 

或轉發郵件項目見NameSpace.GetSharedDefaultFolderMethod (Outlook)on MSDN

+0

謝謝,只是澄清 - 我有多個交易賬戶鏈接到一個Outlook配置文件。就其本身而言,我的VBA代碼只能在主交易所賬戶上操作,但我希望能夠指定它對哪個賬戶起作用。此代碼是否可以實現此目的我在實施時遇到問題。我只需要設置變量並調暗,然後它應該工作? –

+1

是和是,請參閱編輯答案。我不知道你想做什麼,但試着玩這個代碼,如果你仍然有問題,用你的代碼完整的代碼發佈新的問題。 – 0m3r

+1

@JoshuaPatterson再次更新 – 0m3r

相關問題