Hey, I enjoyed it. It was an interesting little challenge. I hope you don't mind that I extrapolated a bit about the direction you were headed. I figured this was related to a previous thread. Most of the code is for tweaking the UI. Sorry for the lack of comments! I'll try to explain a little what's going on.
Surprisingly, there doesn't seem to be anything in the API to determine if a note is part of an annotation group, or to find the members of an annotation group. The only things I could find related to groups were create, remove, and remove item. All of those work on the current selection set, so once you create a group and change the selection set there is no way to programmatically figure out what notes/balloons are part of that group. I had to sort of create my own method of retrieving the group members. That's what the stuff about SerialString is all about. Each annotation of a SW drawing has a unique name, which you can change programmatically. When creating a new balloon/note group, this macro generates a new "serial number", which is just a string that will be part of the name of each member of the group. Every serial number starts with "HandleNote" so that the program can later determine if any given note is part of a group. The numbers that follow are just the date and time (down to the hundredth of a second or so) that the group was created. That ensures that every serial number is unique. The members of the group are named with a prefix denoting which member they are, followed by the serial number. "Bl_" is the prefix for the balloon member, "Bt_" is the bottom note, etc. Once that creation process is completed, you have five notes (one of them being a balloon) with the same name except for the first two characters. This allows the program to later locate all the members of a particular group, even after closing the macro, closing the file, closing SW, etc. The members can even be found if the user un-groups the group.
All of the code in the NewSelectionNotify function is related to finding members of a group. In order to treat the entire group as a unit, this code runs every time the user changes the selection set. There are basically 3 possibilities when a user makes a selection. This is not the order that the macro checks in, but they are:
1. The selection set contains more than 1 item or it is a non-note item. In this case, the the "Add Note" button is disabled, and the macro does nothing.
2. The selection is a note that is a balloon, but that balloon is not already part of a group, determined by whether or not the string "HandleNote_" is part of the name. In that case, the "Add Note" button is enabled to allow the user to create a group for that balloon.
3. The selection is any member of an existing group (again determined by the presence of "HandleNote_" in the name). If this is the case, the macro then searches all annotations on the current sheet for the remaining members of the group, based on matching the entire serial number. A note object is set for each matching note found, based on the first two letters of the note name. These note objects will later be manipulated by the "Add Note" code. After the search, the macro checks to see if it found a balloon as part of the group. If there was no balloon (meaning the user at some point un-grouped and deleted the balloon), the macro stops. The reason for this is that the location of the balloon determines the locations of the notes. If the balloon is gone, the group is effectively lost. If the balloon is found, then the macro loads the text from whatever group members were found into the text boxes of the form and enables the "Add Note" button.
The "Add Note" code was modified to update any notes that were already existing. These existing notes were found back in the NewSelectionNotify code. Any notes that were missing (maybe un-grouped and deleted by the user) are re-created. Even if the text box is blank, a note is still created. I probably should have made it where a blank box actually creates a note with a single space rather than an entirely blank note so that the ugly "blank note" x-ed out box doesn't show up.
Hope that explanation helps a bit!
-handleman, CSWP (The new, easy test)