PDA

View Full Version : Dismiss the "Find and Replace" dialog with VBA?



RichG1
03-03-2013, 03:51 PM
I routinely work with a large document in Word 2003 with several big tables with rows that are generally sized such that most of the text in the cells is not visible (e.g. row height is set to 12 points while the cell contains hundreds of lines of text). This row sizing is intentional and convenient for my purposes. However, when I search the document using the ordinary "Find and Replace" (F&R) dialog and a match is found in one of these "shortened" rows, the "found" selection is usually not visible (because of the short row sizing). When this happens, I'd like the row to autosize automatically so I can see the "found" selection, and then otherwise continue with the ordinary working of the F&R dialog (i.e. keep the dialog open and await input).

I had hoped to solve the problem by setting up a WindowSelectionChange event handler in conjunction with the F&R dialog. (The handler checks the location of a new selection and autosizes as necessary). However--although my WindowSelectionChange event handler gets triggered by selection changes induced by the F&R dialog--the handler can't autosize rows while (as the error says) the F&R dialog is open.

OK, I thought, let's automate a way to dismiss the F&R dialog--then autosize the row and bring the dialog back up. But I can't find a way to dismiss the F&R dialog via VBA. Neither SendKeys "{ESCAPE}" nor SendKeys "%{F4}" works and I can't seem to find another way.

My narrow question: Is there a way to dismiss the F&R dialog with VBA?

My broader question: Is there a better, different way to get the functionality I'm looking for? (i.e. without resizing the rows in advance or creating my own userform)

Thanks very much for your help.

-Rich