PDA

View Full Version : Solved: Undefined Dialog; How to hide???



AndrewPerl
04-20-2006, 07:35 AM
I have written the following code to format mainframe screen captures for our technical writers and business analysts.


Sub Format3270Screen()
'
' Format3270Screen Macro
' Macro created 4/19/2006 by dtxxxxx
Dim strTemp As String

'Is the last character of the selection a paragraph mark?
'If so, then move the selection back one character;
'This ensures that the screen capture will be formatted as a single paragraph

strTemp = Selection.Text
If Right(strTemp, 1) = vbCr Then Selection.MoveEnd _
Unit:=wdCharacter, Count:=-1
'Clear formatting parameters for Find and Replace options
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

'Set parameters for Find and Replace
With Selection.Find
.Text = "^p"
.Replacement.Text = "^l"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

'Execute the Find and Replace and apply "3270 Screen" style to selection
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Style = ActiveDocument.Styles("3270 Screen")
End Sub


The problem arises when the code executes the replace all. A dialog box appears stating, "Word has finished searching the selection. X replacements were made. Do you want to search the remainder of the document?" The user has a choice of selecting Yes or No. I want to be able to prevent the user from selecting Yes. Is this possible????

Andrew Perl
Kansas City

TonyJollans
04-20-2006, 08:06 AM
Hi Andrew,

You get the message because you have .Wrap = wdFindAsk. If you change it to .Wrap = wdFindStop the message shouldn't appear and the Find/Replace will operate only on its Range.

Tecnik
04-20-2006, 08:28 AM
Thanks for that Tony. I had the same problem a few weeks ago and wondered if there was a way round it. That was before I'd found this forum so didn't ask.

Nick

TonyJollans
04-20-2006, 09:14 AM
Thanks for that Nick.

I really like it when answers help other people as well as the questioner. It makes answering so much more worthwhile.

AndrewPerl
04-20-2006, 09:20 AM
Thanks to everyone that replied. I discovered the .Wrap = wdFindStop solution about 45 minutes after I posted my message. In the meantime, I had tried SendKey (doesn't work for this), and a few other items.

This goes to show that VBA usually gives you multiple ways to accomplish a task. The problem is finding a solution that works best. I have found this forum to be a great tool. I always try to do a search for similar issues before I post a question, this usually helps out.

Once again... thanks everyone!!!!

Andrew Perl
Kansas City

Tecnik
04-21-2006, 01:30 AM
Hi Andrew,

Just thinking back to when I had the same problem I found the answer here:-

http://www.jojo-zawawi.com/code-samples-pages/code-samples.htm

Under section 'f' there's this one 'Find, Replace Hard Returns With Manual Line Breaks Within Selected Text:'

As you can see there are some nice snippets. You may have already found this, if not, hope it's of some use.

Nick

geekgirlau
04-21-2006, 02:29 AM
Hi Andrew,

I've taken the liberty of marking the thread as "solved" (please let me know if this is not the case).