InputBox Help

L

LEU

I have the following macro that finds a word in my document then bolds and
Caps it. My problem is if I call the macro and try to close it using the red
close box in the upper right corner of the InputBox the macro blows up. How
do I tell it to close if the close box is clicked?


Sub FindWord()
Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
..Text = InputBox("Word to Bold and Cap:")
..MatchWholeWord = True
While .Execute
Select Case SearchRange.Style
Case "Hd1", "Hd2", "Hd3", "Hd4"
SearchRange.Font.AllCaps = True
SearchRange.Font.Bold = True
End Select
Wend
End With
End Sub
 
D

Doug Robbins - Word MVP

Insert

If .Text = "" Then
Exit Sub
End If

after the InputBox statement.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

It would only work if no text had been entered into the Inputbox.

You may have to use a userform instead of an input box as then you can use
the method in the article "Intercept the Close button (X) in the title bar
of a user form" at:

http://www.word.mvps.org/FAQs/Userforms/InterceptCloseButton.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

Thanks for the help. I did create a userform and used the method in the
article "Intercept the Close button (X) in the title bar of a user form"

LEU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top