views:

2427

answers:

1

I have a TreeView within a UserForm in Excel.
When a Node is selected from the TreeView, a ListBox is populated with data.
When an item in the ListBox is double-clicked, a separate UserForm is shown which allows the user do to stuff.
Once the user returns back to the TreeView UserForm, I want the Node that was selected previously to be highlighted.

The problem is that the UserForm basically resets itself, and I can't figure out how to select a Node with VBA.

I'm at the point where I'm debating on whether or not I can just manually fire a NodeClick event, as everything else I've tried has failed.

Any tips?

+1  A: 

You have several options. First, when the TreeView UserForm displays the second UserForm, you either need to:

  1. Save the ID of the selected node (use a form-level or module-level variable). Then you need to write a method to select the node upon return to the form. IIRC, you need to have a unique 'Key' or ID for each node element and then use TreeView.Select for the node returned from TreeView.FindNode. -- or --
  2. Hide the TreeView UserForm instead of closing it (Me.Hide). When the second UserForm is closed (or OK/Cancel pressed), then show the TreeView UserForm again (TreeViewForm.Show).
Ryan