Hi Ray,
The next stage of rewriting your macros to get rid of flicker is to avoid
using the Selection, and use a Range variable instead.
Most methods that apply to the Selection also apply to a Range.
(Unfortunately not quite all, otherwise the process that I'm going to
describe would be completely automatic)
To use a Range instead of the Selection, put the following at the start of
your macro.
Dim myRange as Range
Set myRange = Selection.Range
(You can set it to anything else you like, but this gives you the closest
match to what your macro is doing at the moment)
Next, go through your macro, and wherever you see the Selection keyword,
replace it with myRange.
Next, go through your macro looking for the Select method. You have to
replace any line with a Select method so that is uses Set myRange =
something instead. So, for instance
ActiveDocument.Tables(1).Range.Select
would become
Set myRange = ActiveDocument.Tables(1).Range
There are some methods which apply only to the Selection. The most commonly
used ones are the HomeKey and EndKey methods. These can be replaced by using
the Move method with appropriate parameters.
Once you have done this, your macro will have much less screen flicker, and
will probably run a good deal faster as well.
There are a few cases where you really need to use the Selection. These
include
1. If you are dealing with lines (as opposed to paragraphs)
2. If you are using the predefined bookmarks such as \Page, which are
defined relative to the selection.
Once you learn to love Ranges, you can find that they are very a powerful
tool for some kinds of macros. This is because, while you are limited to one
selection, you can have as many Range variables as you want to define. If
you want to have a temporary placeholder, just define a range object for it,
and come back to it later.
If you get stuck with converting any particular bit of code, post back here
and we'll help you fix it.
--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email
"ray" <liang
...@hotmail.com> wrote in message
news:O4SFdlWtBHA.1228@tkmsftngp04...
> Hi Mark,
> Thank you very much for your very informative reply.
> I have a number of Word 6 macros, which have been converted into Word 2000
> VBA format automatically upon being executed in Word 2000.
> You are correct that NextCell is a Word Basic command, so I follow your
> advice and recode all statements in VBA. In other words, I get rid of all
> references to the WordBasic object in my macros.
> The flickering problem improves a bit, but it is still there.
> After some experimenting, I find that if a table has more columns than the
> screen can accommodate, the follow code will result in a flickering screen
> if the selection moves into an invisible part of the table and back:
> Application.ScreenUpdating = False
> Selection.MoveRight unit:=wdCell, Count:=10
> Selection.MoveLeft unit:=wdCell, Count:=10
> Application.ScreenUpdating = True
> However, if the relevant cells of the table (in the above code, the eleven
> cells concerned) are all visible in the screen, there will be no
flickering.
> To circumvent the problem, therefore, I precede my macros with the
following
> statement in order to 'bestfit' the entire table:
> ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
> This is of course not a genuine solution to the problem, because I don't
> think that's what the ScreenUpdating command is supposed to work.
> Further suggestions are most welcome!