VBA Outlook Table getNextRow() error using namespace schemas

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I am trying to pull information from emails i have collected from an advance search. If I use the basic schema names like subject everything works but if i use the schema reference (ie, http://schemas.microsoft.com/mapi/proptag/0x10F4000B) directly it draws an error (5 : Invalid procedure call or argument). See the code below:

Code:
Public Sub SearchOutlook()    
    'Create Email
    'Generate Outlook Email for L&E
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim QuitNewOutlook As Boolean
    Dim Session As Outlook.Namespace
    Dim ExchangeStatus  As OlExchangeConnectionMode
    Dim Scope As String
    Dim Filter As String
    Dim MySearch As Outlook.Search
    Dim MyTable As Outlook.Table
    Dim nextRow As Outlook.row
    m_SearchComplete = False
    
    On Error Resume Next
        Set OutApp = GetObject(, "Outlook.Application")
    On Error GoTo OutlookErrors
  
    If OutApp Is Nothing Then
        Set OutApp = CreateObject("Outlook.Application")
        QuitNewOutlook = True
    End If
    
    Set Session = OutApp.GetNamespace("MAPI")
    Session.Logon
    
    'We need to ensure outlook is fully connected
    ExchangeStatus = Session.ExchangeConnectionMode
    If ExchangeStatus <> 700 Then GoTo OutlookErrors
    
    Set OutlookEventClass.oOutlookApp = OutApp
        
    'set scope
    Scope = "'" & OutApp.Session.Folders("MMCratesetting@cms.hhs.gov").FolderPath & "'"
    
    'Establish filter - DASL schemas below:
    'Message ID http://schemas.microsoft.com/mapi/proptag/0x1035001E = <blah.blah@blah.com>
    'Subject urn:schemas:httpmail:subject ci_phrasematch 'blah' - Our store uses instant search
    'Body urn:schemas:httpmail:textdescription ci_phrasematch 'blah'
    'From urn:schemas:httpmail:fromemail
    'To urn:schemas:httpmail:to
    'cc urn:schemas:httpmail:cc
    
    Dim SubjectsToSearch() As String
    SubjectsToSearch = Split("Virginia,Va", ",")
    
    Filter = SubjectSearchSchema(SubjectsToSearch, OutApp.Session.DefaultStore.IsInstantSearchEnabled)
    
    Set MySearch = OutApp.AdvancedSearch(Scope, Filter, True, "MySearch")


    'loop until event triggers that search is complete
    While m_SearchComplete <> True
        DoEvents
    Wend
    
    Set MyTable = MySearch.GetTable


    Do Until MyTable.EndOfTable
        Set nextRow = MyTable.GetNextRow()
        Debug.Print nextRow("Subject") & nextRow("http://schemas.microsoft.com/mapi/proptag/0x10F4000B")
    Loop
    
    If QuitNewOutlook Then
        OutApp.Quit
    End If
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    'Set ExchangeStatus = Nothing Possible Memory Leak?
    
OutlookErrors:
        
            Set OutMail = Nothing
            'Set ExchangeStatus = Nothing Possible Memory Leak?
            If Not OutApp Is Nothing And QuitNewOutlook Then
                OutApp.Quit
            End If
            Set OutApp = Nothing
    


End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,581
Messages
6,120,372
Members
448,957
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top