![]() |
|
#1
|
||||
|
||||
![]()
This sounds fairly straightforward. Can we assume that the 'lines' you refer to are in fact paragraph's? There are no 'lines' in a Word document, other than as an artefact of text flow.
Code:
Sub Macro1() Const strWord As String = "word to find" Dim oRng As Range Dim oFind As Range Set oFind = ActiveDocument.Range With oFind.Find Do While .Execute(FindText:=strWord, MatchCase:=True, MatchWholeWord:=True) oFind.End = oFind.Paragraphs(1).Range.End Set oRng = oFind.Next.Paragraphs(1).Range oRng = Replace(oRng, "(", "") oRng = Replace(oRng, ")", "") oFind.Collapse 0 Loop End With lbl_Exit: Set oFind = Nothing Set oRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#2
|
|||
|
|||
![]()
Yes, that worked beautifully. Thank you!
I was looking up about working with lines and didn't know about the paragraphs thing which might put me on the right track. Now I've done what I needed to I'll pick this apart and see how it works... |
#3
|
|||
|
|||
![]()
One last question on this one: how can I restrict the running of this macro to the current section? I've played around with Set oFind = ActiveDocument.Range(Sections(wdActiveEndSectionNu mber)) but I just keep getting errors.
Thanks. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
VelmaD | Word | 1 | 03-18-2014 05:41 PM |
![]() |
Stokkers | Word | 1 | 06-12-2013 04:21 AM |
![]() |
tinfanide | Word VBA | 3 | 04-27-2012 09:48 AM |
![]() |
namishtiwari | Outlook | 1 | 04-21-2009 11:21 PM |
![]() |
EtienneOBrien | Word | 3 | 12-24-2008 07:05 AM |