Refer to Current Doc in EOF Do...Loop

P

Pendragon

Word 2003

Very simple. In writing a Do....Loop, I need to refer to the Current
Document. The following gives me an error - I need to have an integer or
variable for EOF(). How do I refer to the current document in the EOF?

Do while not EOF(<<HELP>>)
blah
blah
blah
Loop

:)

Thanks.
 
J

Jezebel

EOF() doesn't apply to documents at all. It's used if you are reading a file
opened for random or sequential input -- the argument is the file number
used when opening the file ...

Dim pFileNum as long
pFileNum = Freefile
Open MyFile for input as pFileNum
Do
blah blah
Loop until EOF(pFileNum)


Looping through a document depends on what objects you are looking at, eg

Dim pPar as Word.Paragraph
For each pPar in ActiveDocument.Paragraphs
blah blah
Next
 
D

Doug Robbins - Word MVP

Tell us exactly what it is that you want performed until EOF

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Pendragon

Doug,

I have a set of documents that need to be "cleaned" so others may use them
for their processes, one of which is to import the data in the word file into
access. Part of the reason I have to clean the word document (instead of
simply bringing the info into Access) is because of some hyperlinks in the
document. I have to extract specific info within the field codes and this
info is not accessible once imported into access (only the hyperlink
"caption" or alias is seen).

I will open each document and then run a macro to clean the document, so
it's important that the event below (and all of the other fixes I will add as
well) repeats until the end of the document is reached.

If I just perform a Do...Loop without reference to EOF, will the loop stop
at the end of the document or will it just continue to run and freeze the
document on me? Otherwise, I would still like to know how to reference the
end of a document for this loop. Thanks!

Do While Not EOF(<<what goes here, or how should this loop be constructed?>>)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "("
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

Selection.Find.ClearFormatting
With Selection.Find
.Text = "-"
.Forward = False
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.TypeText Text:=vbTab

....
....
(other formatting search/replace/typetext will follow)

Loop
 
P

Pendragon

This is about the Community Newsgroups, but perhaps you can help....

I used to be able to double-click on a post (yours, for example), and scroll
through the posts and click Yes on your post being helpful. Now when I
double-click, the new window appears but there is no right-side scroll bar to
get down to your message, or any other messages below it. So I am not
currently able to validate any responses.

Ideas? Has Microsoft been messing around with the layout and design again?
 
D

Doug Robbins - Word MVP

Here are a couple of bits of code developed for other posters that will show
you how you go about doing an edit find then something right through a
document.

Sub aa()

Dim i As Long, myrange As Range
i = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}:[0-9]{2}:[0-9]{2}", _
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
myrange.Text = Left(myrange.Text, 6) & Format(i, "0#")
i = i + 1
Loop
End With

End Sub

Sub aaa()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^l([0-9]{2}.[0-9]{2}.[0-9]{4})",
ReplaceWith:="^p\1", _
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^l", ReplaceWith:=" ", _
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="([0-9]{2}:[0-9]{2}) ([A-Z]{1})",
ReplaceWith:="\1^t\2", _
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="(.[0-9]{4}) ", ReplaceWith:="\1^t", _
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="(.[0-9]{4})^t([A-Z]{1})",
ReplaceWith:="\1^t^t\2", _
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
ActiveDocument.Range.ConvertToTable Separator:=vbTab, NumColumns:=3

End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top