We help IT Professionals succeed at work.
Get Started

In Word VBA, how to combine one selection to another selection executed from find

Ashish Bist
Ashish Bist asked
on
271 Views
Last Modified: 2016-09-25
I have a document where question and answer have different styles assigned to each (for question "*Questions" and for answer "Normal"), answer can have multiple paragraphs or even image, so basically I need code to find/search a particular word in document and when found, code need to select from start of that question till the end of its answer (or start of next question). I have code in break but somehow could not able to compile it (not able to combine selection form Previous_Question till Next_Question). code goes like this:

 Sub Previous_Question()

 Selection.Find.Style = "*Questions"
 Selection.Find.Forward = False
 Selection.Find.Execute

 End Sub

 Sub Next_Question()

 Selection.Find.Style = "*Questions"
 Selection.Find.Forward = True
 Selection.Find.Execute

 End Sub


 Sub Find_Word()

 Selection.Find.ClearFormatting
 With Selection.Find
 .Text = InputBox(sPrompt, sTitle, sDefault)
 End With
 Do While Selection.Find.Execute
 Selection.StartOf Unit:=wdParagraph

 Selection.MoveEnd Unit:=wdParagraph
 sBigString = sBigString + Selection.Text
 Selection.MoveStart Unit:=wdParagraph
 Loop
 Documents.Add DocumentType:=wdNewBlankDocument
 Selection.InsertAfter (sBigString)

 End Sub

Open in new window

Please help!!!

Edit: Code put into a snippet box using the CODE item in the comment editor toolbar. GrahamSkan
Comment
Watch Question
Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE