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 / May 2006

Tip: Looking for answers? Try searching our database.

Word hands on selection.MoveEndWhile with comments

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 03 May 2006 20:15 GMT
Happened with Word 2003.

Create the following Word document

   AAA<p>
   <p>
   <p>

where <p> is the paragraph marker.

Select the whole document and do:

   selection.MoveEndWhile Chr(13), wdBackward

Works fine.

Now, select the 1st line (the AAA) and add a comment to it.

Again, select the whole document and do:

   selection.MoveEndWhile Chr(13), wdBackward

Word hangs.

How can I overcome that?
Doug Robbins - Word MVP - 04 May 2006 04:59 GMT
Avoid using the Selection.  What is it that you are actually trying to do?

Signature

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

Happened with Word 2003.

Create the following Word document

   AAA<p>
   <p>
   <p>

where <p> is the paragraph marker.

Select the whole document and do:

   selection.MoveEndWhile Chr(13), wdBackward

Works fine.

Now, select the 1st line (the AAA) and add a comment to it.

Again, select the whole document and do:

   selection.MoveEndWhile Chr(13), wdBackward

Word hangs.

How can I overcome that?
Alex - 04 May 2006 15:16 GMT
> Avoid using the Selection.

Pardon?

I was using the selection to illustrate, the actual code uses a range.

> What is it that you are actually trying to do?

I am trying to strip empty paragraphs from the beginning and end of a range (using MoveEndWhile and MoveStartWhile).

This is a part of a Word add-in that processes and transforms marked parts of a user-created document into a format that one of our applications can digest.

My current "solution" is something like (translated to VBA):

Sub trim(rng As Range)
   rng.MoveStartWhile vbCr, wdForward
   If rng.Comments.Count > 0 Then
      While rng.Characters.Last.Text = vbCr
         rng.MoveEnd wdCharacter, -1
      Wend
   Else
      rng.MoveEndWhile vbCr, wdBackward
   End If
End Sub

but it looks ugly.
Cindy M  -WordMVP- - 04 May 2006 17:15 GMT
Hi Alex,

Well, FWIW I'm able to duplicate the problem you describe. From what I can see in the VBA-Editor, it's not so much that Word crashes, but that the macro goes
into an unending loop. I'm guessing it gets into a comment range and can't get out... So your solution, as ugly as it seems, is probably as good as anything
else.

> I am trying to strip empty paragraphs from the beginning and end of a range (using MoveEndWhile and MoveStartWhile).
>  
[quoted text clipped - 14 lines]
>  
> but it looks ugly.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
Tony Jollans - 05 May 2006 20:21 GMT
When I first saw this, I tried it quickly and where there should have been a
chr(5) for the comment, I found a zero length character (range); I vowed to
come back and look later. Then sometime while I was out, my computer crashed
(USB problem unrelated to Word). Since restarting and restarting Word I am
completely unable to reproduce it. In normal circumstances I would put it
down to some sort of corruption but if you get it repeatedly there must be
circumstances which cause it - at the moment I don't know what they may be.

--
Enjoy,
Tony

> Hi Alex,
>
> Well, FWIW I'm able to duplicate the problem you describe. From what I can see in the VBA-Editor, it's not so much that Word crashes, but that the
macro goes
> into an unending loop. I'm guessing it gets into a comment range and can't get out... So your solution, as ugly as it seems, is probably as good as
anything
> else.
>
> > I am trying to strip empty paragraphs from the beginning and end of a range (using MoveEndWhile and MoveStartWhile).
> >
> > This is a part of a Word add-in that processes and transforms marked parts of a user-created document into a format that one of our applications
can digest.

> > My current "solution" is something like (translated to VBA):
> >
[quoted text clipped - 17 lines]
>
> This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
 
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.