Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Deleting lines with VB Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dado_maker - 31 Dec 2004 00:26 GMT
After finding a line that contains a word, how do I delete the whole
line with VB code?  The line can end with a Paragrapgh marker or a line
break.

Thanks,
dado_maker
Greg Maxey - 31 Dec 2004 01:19 GMT
dado_maker,

This can most likely be improved, but seems to work.  This macro looks for
the string ????? in a paragraph object.  If found, then is looks for a line
break.  If the line break "is not" found then the whole paragraph
(supposedly a single line paragraph in your case) is deleted.  If a line
break is found, then the the paragraph range is set to myRange, myRange is
then collasped then the end is moved to the line break + 1 (or then end of
the line including the break) and myRange is deleted.

Sub ScratchMacro()
Dim myRange As Range
Dim oPar As Paragraph
For Each oPar In ActiveDocument.Paragraphs
If InStr(oPar.Range.Text, "?????") Then
 If InStr(oPar.Range.Text, Chr(11)) Then
   Set myRange = oPar.Range
   myRange.Collapse
   myRange.MoveEndUntil (Chr(11))
   myRange.MoveEnd Unit:=wdCharacter, Count:=1
   myRange.Delete
 Else
 oPar.Range.Delete
 End If
End If
Next

End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> After finding a line that contains a word, how do I delete the whole
> line with VB code?  The line can end with a Paragrapgh marker or a
> line break.
>
> Thanks,
> dado_maker
dado_maker - 31 Dec 2004 06:06 GMT
Greg,

Thanks!  Is there a VBA for MS Word out there you would recomend?

Thanks,
dado_maker

> dado_maker,
>
[quoted text clipped - 35 lines]
> > Thanks,
> > dado_maker
Greg Maxey - 31 Dec 2004 17:09 GMT
dado_maker,

I haven't read any books on VBA.  I don't know much and all that I do know
is from diving in to these newsgroups, asking lots of questions, and reading
the material at the MVP site.

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Greg,
>
[quoted text clipped - 43 lines]
>>> Thanks,
>>> dado_maker

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.