Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 05-06-2021, 05:08 AM
PassengerBird PassengerBird is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2013
Novice
How to perform (Find in Main Document) with VBA
 
Join Date: May 2021
Posts: 5
PassengerBird is on a distinguished road
Post How to perform (Find in Main Document) with VBA


Hello professionals, shortly I want to perform (Find in Main Document), so that all results would be selected in the main document with the VBA, it would be look like this example
تعليق توضيحي 2021-05-06 140144.png

تعليق توضيحي 2021-05-06 140315.png
Please don't tell me that it isn't possible, because I saw it in plugin, and I believe that everything done in Program UI could be done in VBA.
thanks in advance
  #2  
Old 05-06-2021, 05:23 AM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,213
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

This is a trivial undertaking. What have you tried?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #3  
Old 05-06-2021, 07:41 AM
PassengerBird PassengerBird is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2013
Novice
How to perform (Find in Main Document) with VBA
 
Join Date: May 2021
Posts: 5
PassengerBird is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
This is a trivial undertaking. What have you tried?
thanks for your replay @macropod, I really appreciate that, what I have tried is very trivial like me.
Code:
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "the VBA"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        Do While Selection.Find.Execute
            Selection.ExtendMode = True
        Loop
    End With
for sure this doesn't work, but if it works (with some little help from you) it will be a base for what I really want to do.
  #4  
Old 05-06-2021, 07:44 AM
PassengerBird PassengerBird is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2013
Novice
How to perform (Find in Main Document) with VBA
 
Join Date: May 2021
Posts: 5
PassengerBird is on a distinguished road
Default

Quote:
Originally Posted by PassengerBird View Post
Code:
        .Wrap = wdFindContinue
I'm sorry this will do an infinite loop

the correct should be:

Code:
        .Wrap = wdFindStop
  #5  
Old 05-06-2021, 02:10 PM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,213
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Even the macro recorder would record the code you need...

Somewhat more sophisticated:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String
Options.DefaultHighlightColorIndex = wdYellow
StrFnd = InputBox("What is the text to highlight?")
If Trim(StrFnd) = "" Then Exit Sub
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Replacement.Highlight = True
  .Text = StrFnd
  .Replacement.Text = "^&"
  .Format = True
  .Forward = True
  .MatchCase = True
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #6  
Old 05-06-2021, 02:40 PM
PassengerBird PassengerBird is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2013
Novice
How to perform (Find in Main Document) with VBA
 
Join Date: May 2021
Posts: 5
PassengerBird is on a distinguished road
Default

I really appreciating your efforts with me, but I think you didn't get what I want to do, I don't want to highlight the results, I need to (Select them), (do multi-selection) like the UI process does when I press (Find In Main Document), please look one more time to the original post and give me some help, thanks in advance
  #7  
Old 05-06-2021, 03:54 PM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,213
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Well, if you wanted the hit highlight - as shown in the dialogue box you posted a screenshot of, you should have said so. And, as per my previous reply, even the macro recorder would give you the code for that.

Somewhat more sophisticated:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String
StrFnd = InputBox("What is the text to highlight?")
If Trim(StrFnd) = "" Then Exit Sub
With ActiveDocument.Range.Find
  .ClearFormatting
  .Format = True
  .Forward = True
  .MatchCase = True
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .HitHighlight StrFnd, Options.DefaultHighlightColorIndex
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #8  
Old 05-06-2021, 06:09 PM
PassengerBird PassengerBird is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2013
Novice
How to perform (Find in Main Document) with VBA
 
Join Date: May 2021
Posts: 5
PassengerBird is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Well, if you wanted the hit highlight - as shown in the dialogue box you posted a screenshot of, you should have said so. And, as per my previous reply, even the macro recorder would give you the code for that.
Which part of my post that I said in it that I need to highlight the results, obviously in the last post I said that (I don't want to highlight it, I just need to select them like I prees the find in main document button), I think that I was very clear although my first language is not English.
  #9  
Old 05-06-2021, 06:57 PM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,213
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Quote:
Originally Posted by PassengerBird View Post
Which part of my post that I said in it that I need to highlight the results, obviously in the last post I said that.
The whole point, of course, is that you did not say clearly in your first post that that's what you wanted to achieve.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #10  
Old 05-07-2021, 01:36 PM
macropod's Avatar
macropod macropod is offline How to perform (Find in Main Document) with VBA Windows 10 How to perform (Find in Main Document) with VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,213
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Now cross-posted at: ms word - How to perform (Find in Main Document) with VBA - Stack Overflow
in spite of being answered here!!! And with no acknowldgement of this thread.
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
Thread closed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to create a user form and populate it with a field from the main document? NMGMarques Word 3 02-12-2020 06:08 PM
How to perform (Find in Main Document) with VBA Find currency amounts in Word doc, perform sum GWTJR Word VBA 3 10-15-2017 02:22 PM
Macro to find a word in first row of table and then perform two macros hmsrose Word VBA 5 01-30-2015 12:17 AM
Can Word highlight the same text in the Reviewing Pane as in the main document? wordistheword Word 4 09-09-2013 04:50 AM
Connecting documents to main document themangoagent Word 1 08-07-2009 10:15 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft