Results 1 to 7 of 7
  1. #1
    Lounger jpl's Avatar
    Join Date
    Jun 2002
    Location
    England
    Posts
    45
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    The following code (running in a Word template) successfully displays the first line of a Note attached to a Contact Item:

    Set objNotesColl = objContactItem.Attachments
    If objNotesColl.Count > 0 Then
    MsgBox objNotesColl.Count & " items found for " & objContactItem.FullName
    For Each objNote In objNotesColl
    MsgBox objNote
    Next objNote
    End If

    However, I wish to access the entire contents of the Note (objNote.Body), not just the subject, and this does not work. Nor does reading the Subject explicitly, i.e. "MsgBox objNote" works, but "MsgBox objNote.Subject" results in a run-time error.

    How can the entire contents of a Note be read?

    JPL

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    In my experience, though Outlook Client recognizes attachment types, the Outlook VBA object model does not provide that ability beyond parsing the extension of the attached file name, so you can't access objNote.Body. (I'd like to be wrong, I've tried this before; it's equally frustrating that Word cannot directly open a saved Outlook *.msg file, a format in which an email message and a note can be saved.)

    IMO your best bet is to save the note as a text file to a temporary location, then read the text from that file.

    Dim objNotesColl As Outlook.Attachments
    Dim objNote As Object
    Set objNotesColl = ActiveInspector.CurrentItem.Attachments
    If objNotesColl.Count > 0 Then
    For Each objNote In objNotesColl
    With objNote
    Debug.Print .FileName & "; " & .DisplayName
    .SaveAs Path:=<mypath>, Type:=olTXT
    End With
    Next objNote
    End If

    Perhaps another Lounger has a better idea.
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Lounger jpl's Avatar
    Join Date
    Jun 2002
    Location
    England
    Posts
    45
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    John,

    Thanks for your reply.

    I thought I was just making a silly mistake/omission and am amazed to find the object model does not support the "simple" task I was attempting.

    Saving as a file is a straightforward workaround, although rather messy in nature.

    JPL

  4. #4
    Lounger jpl's Avatar
    Join Date
    Jun 2002
    Location
    England
    Posts
    45
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    ObjNote.SaveAs results in an error:

    "Object does not support this property or method".

    Any ideas?

    JPL

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    Can you post your exact code including variable declarations? It's hard to know if it's an object declaration problem or a syntax issue without seeing more of the code. You can also check what variable type objNote is, and what filename it has, with:

    Debug.Print Typename(objNote)
    Debug.Print .FileName & "; " & .DisplayName

    after objNote is created.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    Lounger jpl's Avatar
    Join Date
    Jun 2002
    Location
    England
    Posts
    45
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    Thanks, John - your question about the object type is the key to the .SaveAs problem. I was too focussed on the NoteItem aspects and was blind to the fact that the object being processed is actually an Attachment.

    Whether objNotesCollection and objNote are defined simply as Objects or explicitly as Outlook.Attachments and Outlook.Attachment respectively, the returned object is an Attachment and so the NoteItem .SaveAs method is not available. (Neither, of course, is what I originally wanted: NoteItem.Body.)

    As the object is an Attachment, it is possible to use .SaveAsFile, but this produces a file containing a NoteItem (filename extension .msg) - not as easy to handle as a text file. I believe it can be opened using CDO, but shall have to start from scratch here as I have not used CDO before.

    Or is it possible to copy or convert an Attachment object to a NoteItem one?

    It is frustrating to find that it appears impossible to get an attached Note directly. (I was expecting the sort of dificulty I had opening sub-folders under the default Contacts folder - trivially simple to open the main Contacts folder, but not immediately obvious how to open folders further down the tree.)

    The code that successfully writes Notes attached to Contact Items into .msg files is shown below:

    Dim colFolders As Outlook.Folders
    Dim fldFolder As Outlook.MAPIFolder
    Dim objContactsCollection As Outlook.Items
    Dim objContact As Outlook.ContactItem
    Dim objMatchingContact As Outlook.ContactItem
    Dim objNotesCollection As Outlook.Attachments
    Dim objNote As Outlook.Attachment

    Set objContactsCollection = fldFolder.Items
    If objContactsCollection.Count > 0 Then
    For Each objContact In objContactsCollection
    Set objMatchingContact = gnspNameSpace.GetItemFromID(objContact.EntryId)
    If <filter criteria are met> Then
    Set objNotesCollection = objMatchingContact.Attachments
    If objNotesCollection.Count > 0 Then
    For Each objNote In objNotesCollection
    With objNote
    .SaveAsFile "C:Xfr" & .FileName
    End With
    Next objNote
    End If
    End If
    Next objContact
    End If

    JPL

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Read contents of Note inserted in Outlook Contact (Office 2003 SP2)

    <img src=/S/drop.gif border=0 alt=drop width=23 height=23> Sorry, I likewise should have known that in Outlook VBA you can .SaveAs an Item, but you can only .SaveAsFile an Attachment; the methods are similar and easily confused (at least, they are by me). And we now recurse to my comment about "it's frustrating that Word can't open an Outlook *.msg file".

    Good luck with CDO - I don't know it but there are a couple of folks here in the VBA forum who do, also you might search http://www.outlookcode.com and http://www.cdolive.com.
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •