Group: microsoft.public.word.vba.general
From: =?Utf-8?B?TlogVkJBIERldmVsb3Blcg==?=
Date: Wednesday, April 09, 2008 4:43 PM
Subject: Re: ending multiple if/with statements

Thanks Jonathan. I'll give this a try. If it works it should stop the screen
from jumping around while the document is building. (Does
Application.Screenupdating = False actually _do_ anything?) However, I'll
probably have to display a "Building document" dialog of some sort now so the
users will know to wait. Some of the documents are rather large and some of
the users' machine rather slooooow...

And thanks Doug for confirming the small error in the line
.Bookmarks("[Bookmark name]").Select
Had me scratching my head for a minute there. ;-D
--
Cheers!
The Kiwi Koder


"Jonathan West" wrote:

>
> "NZ VBA Developer" wrote in message
> news:1012C633-B9DD-4154-A7DC-C2DD4EB8B884@microsoft.com...
> > Here's one example that I use regularly:
> >
> > With ActiveDocument
> > If .Bookmarks.Exists("[Bookmark name]") Then
> > .Bookmarks("[Bookmark name]").Select
> > With Selection
> > .Text = "Some text..."
> > .Bookmarks.Add "[Bookmark name]", .Range
> > End With
> > End If
> > End With
> >
> > Technically I suppose this is sloppy code because of the use of the
> > Selection object. However, I can't seem to find another reliable method
> > for
> > preserving / retaining / reinstating a bookmark after inserting text...
>
> You can avoid the Selection object by using a Range, like this
>
> Dim myRange as Range
> With ActiveDocument
> If .Bookmarks.Exists("[Bookmark name]") Then
> Set myRange = .Bookmarks("[Bookmark name]").Select
> With myRange
> .Text = "Some text..."
> .Bookmarks.Add "[Bookmark name]", .Range
> End With
> End If
> End With
>
> This is generally quicker, and avoids moving the selection.
>
> >
> > That's not really important though. What matters is the nested With
> > statements, which reference completely different objects without ending
> > one
> > before initiating the other. Very cool!
>
> yes, that's a good example of the technique
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
>
>

Safety Articles | Usenet Groups | Usenet News | Bluegrass