Predefined Bookmarks

M

Mahmud

Hi,



I want to do something with code from beginning to end of the document. When
code reaches at the end of document, it will stop. I tried with following
code which seems incorrect because it never shows me the message box saying
"Reached at End of Document", rather the loop continues without stopping.



Sub doSomething()



Selection.HomeKey Unit:=wdStory



Do Until ActiveDocument.Bookmarks("\Sel") =
ActiveDocument.Bookmarks("\EndOfDoc")

Selection.MoveDown Unit:=wdLine, Count:=1

Selection.EndKey Unit:=wdLine

Loop



MsgBox "Reached at End of Document"





End Sub



Is there anyone who can tell me what is wrong and how to fix it, please ?



Thanks in Advance



Mahmud
 
H

Helmut Weber

Hi Mahmud,

there are many better ways than to use the following code:

Sub doSomething()
Selection.HomeKey Unit:=wdStory
Do Until ActiveDocument.Bookmarks("\Sel").start = _
ActiveDocument.Bookmarks("\EndOfDoc").start
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine
Loop
MsgBox "Reached at End of Document"
End Sub

But if it helps, its alright.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Mahmud

Dear Helmut,
Thanks a lot. It helps indeed.
But you mentioned there are many better ways, would you mind (if you have
time, of course) to share at least one with me?
Actually I need something which will stop operation when it reaches at the
end of document.
Thanks again.
Mahmud
 
H

Helmut Weber

Hi Mahmud,

what are you trying to do?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Mahmud

Hi Helmut
I have some files where line breaks are used instead of paragraph.
I will have to delete all those line breaks and make a para. By
doing this, when the code will reach at the end of file, I want it to
stop automatically.

I have several files and each file contains more than 100 pages
all files are in similar format. I am using Office 2003 in WinXP.
Mahmud
 
J

Jay Freedman

Hi Helmut
I have some files where line breaks are used instead of paragraph.
I will have to delete all those line breaks and make a para. By
doing this, when the code will reach at the end of file, I want it to
stop automatically.

I have several files and each file contains more than 100 pages
all files are in similar format. I am using Office 2003 in WinXP.
Mahmud

Mahmud, don't try to "loop from beginning to end". The task you're
doing is best done with a Replace operation, using the ReplaceAll
condition.

If it was just one document, you wouldn't even need a macro -- you
could just use the Replace dialog on the Edit menu. See
http://www.word.mvps.org/FAQs/Formatting/CleanWebText.htm for a
description.

To make a macro so you can repeat the Replace on several documents,
use the macro recorder.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
M

Mahmud

hi jay,

it was helpful. thanks.

mahmud

Jay Freedman said:
Mahmud, don't try to "loop from beginning to end". The task you're
doing is best done with a Replace operation, using the ReplaceAll
condition.

If it was just one document, you wouldn't even need a macro -- you
could just use the Replace dialog on the Edit menu. See
http://www.word.mvps.org/FAQs/Formatting/CleanWebText.htm for a
description.

To make a macro so you can repeat the Replace on several documents,
use the macro recorder.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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