Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple VBA Thing (Outlook XP)

    I need to write a simple piece of code that will allow me to change the color of a currently-selected Note and assign it to a category. So far, I can't find anything out there that tells me how to do that. The only examples I can find on Microsoft's website and in the Help files are how to (supposedly) do it when creating a new item, but not how to do it to one that's already created.
    I thought this would be so easy...
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simple VBA Thing (Outlook XP)

    Something like this?

    Dim olNSP As NameSpace
    Dim olFld As MAPIFolder
    Dim olItm As NoteItem

    Set olNSP = GetNamespace("MAPI")
    Set olFld = olNSP.GetDefaultFolder(olFolderNotes)
    Set olItm = olFld.Items(1)

    With olItm
    .Color = olGreen
    .Categories = "Ideas"
    .Save
    End With

    Set olItm = Nothing
    Set olFld = Nothing
    Set olNSP = Nothing

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

    Re: Simple VBA Thing (Outlook XP)

    Hans, your code will work on the first item in the notes collection, not necessarily the currently active note. (And I now have green notes strewn all over to prove it. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>). This should work:

    Sub setnote()
    Dim olItm As NoteItem
    On Error Resume Next
    Set olItm = ActiveInspector.CurrentItem
    On Error GoTo 0
    If Not olItm Is Nothing Then
    With olItm
    .Color = olGreen
    .Categories = "Ideas"
    .Save
    End With
    Else
    MsgBox "Current item is not Note Item"
    End If
    Set olItm = Nothing
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simple VBA Thing (Outlook XP)

    Frustrating... nether piece of code did anything. They didn't even error out. The second piece told me that I didn't have a note selected (which I most certainly did.) I closed the VB editor, then assigned the macro to the button, then selected a note and clicked on the button... nothin'...
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  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: Simple VBA Thing (Outlook XP)

    Mike, there is a difference between 'selected' and 'active'; my code would not work on a Note that was simply selected in the Folder, it runs only on a Note that is open and has focus (has the cursor). I'll work up code that runs on either any single open item or multple selected Notes in the Folder and post it back here.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simple VBA Thing (Outlook XP)

    Ohhhhhhhhhh...
    Well, then... is there a way to get it to work on an object that's not open? Or, how might I get around the fact that, if I have a note open, it takes the focus away from the active object when I click on a button on the toolbar (to which I've assigned the macro/code.)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  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: Simple VBA Thing (Outlook XP)

    It should have worked on a single Open Note, did you try it? I'll try to get code to work on multiple items.
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simple VBA Thing (Outlook XP)

    The first go 'round, after I initially created that macro, clicking on the button on the toolbar took the focus away from the open Note and nothing happened... at least that's what seemed to be happening. After closing the Outlook session and then re-launching Outlook, it now seems to work. (An odd note, though: the very first time it worked, I did it to a random note. When I removed the "Category" assignment and then tried to manually change the color, I found that the Color option was no longer available for that note! I restarted and everything, and finally had to delete the note and recreate it.)

    Does a note have to be open to change its properties like this? I had originally envisioned a button that I could click on after highlighting a note from the Explorer without having to open it, maybe even run on several selected notes at one time.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

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

    Re: Simple VBA Thing (Outlook XP)

    No, the note does not have to be open. As previously promised, this code should work on either selected items in the Folder, or the Active Note. If you have problems please advise which line errors out and what the error message is:

    Sub setnotes()
    Dim selItmsSel As Selection
    Dim objItem As Object
    Dim lngC As Long

    On Error Resume Next
    If TypeName(Outlook.ActiveWindow) = "Explorer" Then
    Set selItmsSel = ActiveExplorer.Selection
    Else
    Set objItem = Outlook.ActiveInspector.CurrentItem
    End If
    On Error GoTo 0

    If Not selItmsSel Is Nothing Then
    If CBool(selItmsSel.Count) Then
    For lngC = 1 To selItmsSel.Count
    If selItmsSel(lngC).Class = olNote Then
    Call setnoteprop(selItmsSel(lngC))
    Else
    MsgBox selItmsSel(lngC) & " is not Note Item"
    End If
    Next lngC
    Else
    MsgBox "Nothing selected"
    End If
    Else
    If Not objItem Is Nothing Then
    If objItem = olNote Then
    Call setnoteprop(objItem)
    Else
    MsgBox objItem & "is Not a Note Item"
    End If
    End If
    End If

    Set selItmsSel = Nothing
    Set objItem = Nothing
    End Sub

    Private Function setnoteprop(note As NoteItem)
    With note
    .Color = olGreen
    .Categories = "Ideas"
    .Save
    End With
    End Function
    -John ... I float in liquid gardens
    UTC -7ąDS

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simple VBA Thing (Outlook XP)

    I was aware of that, it was just meant to show that it is possible to manipulate an existing item in code. I'm glad you continued the thread while I was busy elsewhere.

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

    Re: Simple VBA Thing (Outlook XP)

    Apologies, considering all that you have taught me Hans, I wouldn't ever impugn your work.
    -John ... I float in liquid gardens
    UTC -7ąDS

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simple VBA Thing (Outlook XP)

    No apologies needed, John!

  13. #13
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simple VBA Thing (Outlook XP)

    Rockin'. This did the trick. Thanks to everyone for the help.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

Posting Permissions

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