How to determine if an Note item is currently displayed?

paulkersey1234
paulkersey1234 used Ask the Experts™
on
How to determine if an Note item is currently displayed? If it's not, then open it, otherwise close it?  How would I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Quality Lead Engineer
Top Expert 2011
Commented:
Hello paulkersey1234,

If you can establish id like in your previous question for startup then try the following substituting for the required id of course.


Regards,

chris_bottomley
Sub testnote()
Dim inspect As Inspector
Dim bolFound As Boolean
Const id As String = "00000000E445099664C94646899BDF4AF261BAFD84B13700"

    For Each inspect In Application.Inspectors
        If inspect.CurrentItem.EntryID = id Then
            bolFound = True
            Exit For
        End If
    Next
    If Not bolFound Then _
        Application.Session.GetItemFromID(id).GetInspector.Activate
    
End Sub

Open in new window

Top Expert 2010
Commented:
Hi, paulkersey1234.

That's a difficult question to answer without more information.  What do you mean by "is currently displayed"?  Does that mean it is the active Outlook window or it is open in any Outlook window?  What if more than one note window is open?  We need to have some idea of how to identify the note you're looking for.  Here are some examples.


'This will test to see if the active inspector windows has a note open.  
If Application.Inspectors.count > 0 Then
    If Application.ActiveInspector.CurrentItem.Class = olNote Then
        'Code for whatever you want to do with an open note'
    Else
        'Code for whatever you want to do if a note is not open'
    End If
End If

'Here is how you would test all inspectors to see if any of them contain notes'
Dim olkInspector As Outlook.Inspector
For Each olkInspector In Application.Inspectors
    If olkInspector.CurrentItem.Class = olNote Then
        'Code for whatever you want to do with an open note'
    Else
        'Code for whatever you want to do if a note is not open'
    End If
Next

Open in new window

Private Sub Application_Startup()
    Dim myOlApp As Outlook.Application
    Dim myNamespace As Outlook.NameSpace
    Dim myItems As Outlook.Items
    Dim myItem As Object
    Dim inspect As Inspector
   
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNamespace = myOlApp.GetNamespace("MAPI")
    Set myItems = myNamespace.GetDefaultFolder(olFolderNotes).Items
   
    For Each myItem In myItems
    id = myItem.EntryID
           For Each inspect In Application.Inspectors
                If inspect.CurrentItem.EntryID = id Then
                   myItem.Close 0
                   GoTo NextItem:
                End If
           Next
           myItem.Display
NextItem:
    Next
   
    Set myCurrentItem = Nothing
    Set myNamespace = Nothing
    Set myItems = Nothing
    Set objApp = Nothing
   
End Sub

Author

Commented:
Great, thanks everybody!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial