0

When I load an e-mail by EntryID, I can add a watch on the MailItem object and get a list of all its properties. But I have to click on each one to see their values. Is there a way to search them all for a string I expect to be somewhere in the properties?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
NewSites
  • 1,402
  • 2
  • 11
  • 26
  • No, you need to specify which particular properties you need to search. Especially since you can have properties of different type (int vs string vs binary etc.) – Dmitry Streblechenko May 25 '23 at 20:58

2 Answers2

0

No, you need to check each property separately. Under the debugger attached you can view the object properties and find the required one for using in the code.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
0

I found that it is possible to list MailItem properties and their values using the Typelib Information thing mentioned here and also the CallByName function.

First you must select: Tools - References - TypeLib Information enter image description here

Sub properties_list(ByVal o As Object)
'must add Tools - References - "TypeLib Information"

  Set t = New TLI.TLIApplication
  Set ti = t.InterfaceInfoFromObject(o)
  Dim mi As TLI.MemberInfo
  
  'needed or else will get invalid procedure call or argument for CallByName with some properties
  On Error Resume Next

  For Each mi In ti.Members
    If mi.InvokeKind = INVOKE_PROPERTYGET Then
      Debug.Print mi.Name & " = " & CallByName(o, mi.Name, VbGet)
    End If
  Next

  On Error GoTo 0
End Sub

It will list properties if you run properties_list(MailItem). So you could use this method to search all the property values for strings.

garbb
  • 679
  • 5
  • 9
  • Under `Outlook > VBA > Tools > References > Available References`, I don't see an item "TypeLib Information". I see a lot of items with names of the form "... Type Library". Is there a certain type library that I need to load for this? – NewSites May 26 '23 at 13:19
  • Weird. Maybe different version of excel? I have 32bit office 365 outlook version 16.0.14326.20738. I added a screencap to my post in case that helps. You might as well try the type library thing and see if it works? – garbb May 26 '23 at 13:48
  • Thanks for the picture of the references list. I don't understand why you mentioned Excel; `MailItem` is in Outlook, not Excel. Anyway, your references list shows a filename of "TLBINF32.dll". I searched for "tlbinf" under "C:\Windows", and it's not there. I'm not in Office 365, but Office running on my computer, not the cloud. Maybe what you're doing is only available under Office 365. Or -- I found a reference that suggests TypLib requires Visual Studio: https://renenyffenegger.ch/notes/development/languages/VBA/Useful-object-libraries/TypeLib-Information/index – NewSites May 26 '23 at 14:51
  • Sorry meant to say outlook, not excel. The one link for the info about the typelib thing mentioned excel so I got confused. – garbb May 26 '23 at 16:25