VBE Find – 2

Dick Kusleika shared VBE Find, a solution that intentionally had no choices and a straightforward UI. [In his post he also pointed out a few limitations with it.] Unfortunately for him, I liked it so much that I enhanced it to the point that he might now be uncomfortable with the bells and whistles. [Among the changes I shared earlier were adding RegEx support, adding a sort UI and the associated Bubble Sort code of a 2D matrix on any number of columns, and the ability to pick up the word containing the cursor.]

This post documents all the changes from the user’s perspective and from a maintenance perspective, and shares the updated file.

In the add-in dialog box, the add-in name is now VBE Helper.

The capabilities other than the VBE Find remain untouched from DK’s version.

Additional code in the OpenClose code module confirms that the add-in can access the VBE.

All the menu (commandbar) changes are now temporary.

As far as the Find capability goes…

The keyboard access is still ‘Alt t k f’. If anyone knows how to assign a custom keyboard shortcut in the VBE…

vbe_find_2

The Find button is gone. It’s no longer needed.

The Cancel button still remains. It’s a small white X on a red background in the top right corner of the form. It remains exclusively to support exiting the form with the Esc key. So, to close the form, use either the Esc key or click the form’s X button or this button.

The form is shown modeless. This means one can interact with the code with the form still active (and the reason why the Find button is not needed).

When the form first shows, it will automatically pick up the current selection (if it does not span a line boundary) or, if there is no selection, the word containing the cursor.

If the Find field contains a token, it will be selected.

Click on any row of the results shown and the code will highlight the search item on that line of code.

The form includes support for finding by ‘whole word’, ‘match case’, and ‘pattern matching’. These are as in the default Find and use the same search mechanism. I find the ‘Pattern Matching’ somewhat less than useful since it doesn’t support the entire Regular Expression feature set.

So, there is the ‘Match with Regular Expression’ option. This uses new code added by me.

If there is an error in the search pattern (either for ‘pattern matching’ or ‘match with regular expression’ the error will be shown in red between the 2 rows of checkboxes.

The result is now sortable on any of 3 columns (module name, procedure name, if any, and line number). The priority of multiple sort columns is left-to-right in the UI. When the last checkbox is unchecked the results are left untouched (i.e., they do not return to the original sequence).

When the userform, i.e., dialog box, is closed, additional code ensures that the user is in the window where s/he was last.

If one changes the active project while the dialog box is still open a subsequent search will search the project that was the active project when the dialog box was first shown. Not the nicest of features but we’ll leave that for version 3.

What else would I like to add? Well, a custom shortcut key combo. But, I don’t know how to do that. And, if I change the code while the dialog box is still open, then, I’d like the results updated, at least when I click in the dialog box again. Unfortunately, I don’t know how to do that either since there is no userform event that triggers when one clicks in a code pane and then clicks back in the dialog box (the Activate event doesn’t work). Nor is there a VBE event to detect a code change.

The updated file.

Tushar Mehta
www.tushar-mehta.com

Posted in Uncategorized

6 thoughts on “VBE Find – 2

  1. Stephen Bullen sent me some sample code to hook a shortcut key into the VBE. It uses a (hidden) userform and a class module.
    Drop me a line if you want it.

  2. jkp: I want it. dkusleika@gmail.com

    TM: What I like about your options is that I’m not forced to use them. They’re there, but it’s all on one form, no hide/show options or any other nonsense. I originally started with a modeless form, but I didn’t like how it loses focus and makes me use the mouse to get it back. So I went to modal and introduced the problem of the closing form designer getting the focus. I can’t win for losing.

  3. Would love to get a copy of the VBE keyboard shortcut userform/class. That’s something I’ve been trying to figure out myself!


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.