Tuesday, March 15, 2016

Troubleshoot:2 questions about a Search loop

2 questions about a Search loop

Hello, folks,
 
I want to make what I THINK would be a pretty straightforward loop. 
It needs to search a document for text between quotation marks, underline the first Find, pause and ask the user if they want to continue (like a regular Word search-and-replace does), and if the user clicks yes, continue the search from right after
the first Find, search for the next Find and underline it, pause again, asking the user if they want to continue, etc.   I'd be grateful for any help.
Thank you, -Lynne.
2 QUESTIONS:
1-How to make the screen show what each Find is, as the macro moves along?
2-How to make the loop continue after the first Find? 
(See With/End With #3, in the code.)
What I’ve got so far works fine, but I don’t know how to make the loop continue after the first Find. 
In the macro, first are the Dims for the Message Box to ask if user wants to continue. 
It has Yes and No buttons.
Next is the Dim for the Search and Replace range.
Then is the SEARCH LOOP. 
It has 3 With/End With statements:  #1 underlines the SearchAndReplaceRng. 
#2 gets rid of underlining of any commas.  #3, I THINK(?), would reset SearchAndReplaceRng to be from after the most recent Find to then end of the document.
Also, the screen needs to show where the Find has paused. 
Right now, it doesn’t.
 
Here’s my code:
Sub TESTForTermByTerm()
'==***========================
'Dims for the Yes/No MsgBox:
Dim Msg, Style, Response, MyString
Msg = "Continue ?"
Style = vbYesNo
'==***========================
'Dim for the Seach/Replace:
Dim SearchAndReplaceRng As Range
Set SearchAndReplaceRng = ActiveDocument.Content
'==***========================
'Search loop:
With SearchAndReplaceRng.Find
  .ClearFormatting
  .Text = "[^0034^0147]*[^0034^0148]" '<-- Search for text between quotes
  .Forward = True
  .Wrap = wdFindStop
  .MatchWildcards = True
  Do While .Execute
'==*** ========================
‘With/End With #1:
        With SearchAndReplaceRng
            .MoveEnd Unit:=wdCharacter, Count:=-1 '<-- .MoveEnd = move LAST UNIT of SearchAndReplaceRng left 1 char, to inside of quote
            .MoveStart Unit:=wdCharacter, Count:=1 '<-- .MoveStart = move FIRST UNIT of SearchAndReplaceRng right 1 char, to inside of quote
            .Font.Underline = True
        End With
'==*** ========================
‘With/End With #2:
        With SearchAndReplaceRng.Find '<--look for any underlined commas and de-underline
            .Text = ","
            .Font.Underline = True
            .Replacement.Text = ","
            .Replacement.Font.Underline = wdUnderlineNone
            .Execute Replace:=wdReplaceAll
        End With
'==*** ========================
‘With/End With #3:   ß HELP?
        With SearchAndReplaceRng
            ‘Move the end of the range to 4 chars after the end of the find, then collapse it?
            .MoveEnd Unit:=wdCharacter, Count:=4 '<-- .MoveEnd = move LAST UNIT of SearchAndReplaceRng right 4 chars 
?
            .Collapse Direction:=wdCollapseEnd    
‘ß Reset range to be from here to end of document 
?
        End With
'==*** ========================
        Response = MsgBox(Msg, Style)
        If Response = vbNo Then    
 'ß if NO to CONTINUE? then
            GoTo STOPNOW       
'ß DROP OUT OF LOOP
        End If
‘                                
‘ß Else, continue with loop...
    Loop
STOPNOW:
End With
End Sub

Solutions to the Problem 2 questions about a Search loop

Download Error Fixer for Free Now

It simplifies the range manipulations if you save the removal of underlines from commas until all the underlines have been put in.
Try it this way:

Sub TESTForTermByTerm()
    Dim SearchAndReplaceRng As Range
   
    Set SearchAndReplaceRng = ActiveDocument.Content
    With SearchAndReplaceRng.Find
        .ClearFormatting
        .Text = "[^0034^0147]*[^0034^0148]" '<-- Search for text between quotes
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        While .Execute
            With SearchAndReplaceRng
                .MoveEnd Unit:=wdCharacter, Count:=-1
                .MoveStart Unit:=wdCharacter, Count:=1
                .Select  ' <-- bring it into view
                .Font.Underline = wdUnderlineSingle
               
                If MsgBox(Prompt:="Continue?", Buttons:=vbYesNo) = vbNo Then GoTo NoComma
               
                .Start = .End + 2  ' <-- next search starting after the current closing quote
                .End = ActiveDocument.Content.End  ' <-- and continuing to the end of the document
            End With
        Wend
    End With
   
NoComma:
    Set SearchAndReplaceRng = ActiveDocument.Content
    With SearchAndReplaceRng.Find
        .Text = ","
        .Font.Underline = True
        .Replacement.Text = ","
        .Replacement.Font.Underline = wdUnderlineNone
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Machine Throttling
  • Click the Start button.
  • In the Search box, type "regedit" (without quotes) and press Enter.
  • Look for the following registry key: "HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\ SQMClient\Windows\DisabledSessions".
  • On the right window pane, delete the subkey: "Machine Throttling".
  • Restart your computer.

Recommended Method to Fix the Problem: 2 questions about a Search loop:

 

 

How to Fix 2 questions about a Search loop with SmartPCFixer?

1. You can Download Error Fixer here. Install it on your system. When you open SmartPCFixer, it will perform a scan.

2. After the scan is finished, you can see the errors and problems need to be repaired. Click Fix All.

3. The Repair part is finished, the speed of your computer will be much higher than before and the errors have been fixed. You can also use other functions in this software. Like dll downloading, windows updating and print spooler error repair.


Related: 1327 Invalid Drive Z Error Code 80004004 Error Code 137 80072ee7 Fix 3315 Error 26 3213 1726 0X6be Error Code 1393 Acaptuser32 dll Error 3050 Biosinfo dll,Fast Solution to Fix Error 1017 Received Logging On To The Standby Error,Installation Error 1706 Error Fixer,Loopback Failure Error - How to Fix,How to Fix Pro Registry Cleaner Error,How to Fix Win 7 Installation Error Code: 0x800705070 Error Quickly,IE 8: Can't Send Page by Email AND Can't Send Link by Email,I can't connect to yahoo.com for online gaming after installing ex9 is there a problem?,c drive says full with 58gb and drive d has 219gb how to fromat drive c for more gb,Automatic Spelling Correction in MS Excel 2007,Attempting to install a financial program and getting error with regsvr32

No comments:

Post a Comment