Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop until end of file

Status
Not open for further replies.

MarieHelene

Programmer
Nov 24, 2005
1
BE
Hi eveyone!
This is my code (with parts in french, sorry):
-----------------------------------------------------------
'tant qu'on n'est pas à la fin du fichier, répéter...
'Do While Not EOF(???)
'Do While Not ActiveDocument.Bookmarks("\EndOfDoc")
'recherche d'un paragraphe en "Heading 4"
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 4")
With Selection.Find
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

doublon = Selection.Text

'comparaison avec le texte de la ligne suivante
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Count:=1
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend

If Selection.Text = doublon And Selection.Style = "Heading 5" Then
Selection.Delete
End If
Loop
----------------------------------------------------------

I need to execute this code (deletion of one of two consecutive repeated lines of text, first line with style "Heading 4", second line with style "Heading 5") from the start to the end of file.
My problem is... what do I have to write after "Do While"?...
Is there a way to get the filenumber of the "ActiveFile" (or to set it) to use with EOF(filenumber)?
If I can use bookmarks ("\EndOfDoc"), how?...
Or maybe is there an easier or simplier way to loop?...
Thank you. ;-)
 
Not sure if I understand the question correctly, but if what you want is to simply delete all paragraphs that are using Heading 4 and Heading 5 styles, then:
Code:
Sub DumpHeading4and5()
Dim oPara As Word.Paragraph
For Each oPara In ActiveDocument.Paragraphs()
 If oPara.Style = "Heading 4" Or _
       oPara.Style = "Heading 5" Then
    oPara.Range.Delete
 End If
Next
End Sub

will do that. It simply checks each paragraph to see if it is Heading 4, or Heading 5, and if it is...deletes it.

Gerry
 
If this is NOT what you are trying to do, please post back with a bit more detail.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top