2016年3月27日星期日

Troubleshooting:2 questions about a Search loop Error

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

Running System Update Readiness Command

On running the System Update readiness Command, it will Detect & Replace Incorrect Registry data with the Correct one. Which may ultimately Solve 2 questions about a Search loop in Windows.

  1. Open CMD as Administrator by Simply Right Clicking on Start button > Command Prompt (Admin).
  2. Now Type or Copy paste "DISM.exe /Online /Cleanup-image /Scanhealth" and hit Enter,
  3. Now again Type or Copy paste this "DISM.exe /Online /Cleanup-image /Restorehealth" and hit Enter.
  4. Close the Command Prompt Window because we are done.

Reboot your Windows & see if error 2 questions about a Search loop is still there.

Note: Your administrator's password might be needed.

Another Safe way to Repair the Problem: 2 questions about a Search loop:

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

1. Download SmartPCFixer . Install it on your system.  Click Scan, and it will perform a scan for your computer. The errors will be shown in the list.

2. After the scan is finished, you can see the errors and problems which need to be fixed.

3. The Fixing part is done, the speed of your computer will be much higher than before and the errors have been fixed.


Related: ,2 pages in a sheet, is it possible to print the first page portrait and the second page landscape?,2010 Mail Merge,3/4 of mt RAM is recognized but If only uses half of it how do i get my desktop to use all of my ram,6.1.7601.2.1.0.256.48 BlueScreen Error Code: BCCode: 50,7 ultimate. no portugues/spansih dictionary for word docs etc?

没有评论:

发表评论

注意:只有此博客的成员才能发布评论。