Move top-left corner of document into view

P

Phil Vern

When I open a document containing a table I do some editing (using VBA) in a
cell off the screen. This causes the document to visually move to the right
to bring the cell onto the screen. Afterwards, I need the top left section of
the document redisplayed on my screen. At the moment, I'm using a workaround
to achieve this - I select cell(1, 1) which is the top left of the document,
insert a period (ie ".") and then delete the period. But, how do I move the
top left corner of the document into view without doing any editing? It would
be much safer for any text already there.

Note: I have also tried turning ScreenUpdating off, but it has no affect on
this.

Thanks for your help.

My current code:

myDocument.Tables.Item(1).Cell(1, 1).Select()
With myDocument.ActiveWindow.Selection
.HomeKey() ' Sets insertion point at start of cell
.Range.InsertAfter(".") ' Inserts a period
.HomeKey(wdLine, wdExtend) ' Selects period
.Delete() ' Deletes period
End With
 
H

Helmut Weber

Hi Phil,

like this:

ActiveWindow.HorizontalPercentScrolled = 0
ActiveWindow.VerticalPercentScrolled = 0

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
C

Chuck

Using Selection to work VBA on your off-screen cell is why your display is
shifting to that cell. Instead use Range and Application.ScreenUpdating, for
example try:

Application.ScreenUpdating = False

With myDocument.Tables(1)
with .Cell(25, 25) 'change cell address
'work VBA magic here
end with
.Cell(1, 1).Range.Select
End With

Application.ScreenUpdating = True
 
J

Jezebel

The better approach here is to avoid the selection object entirely -- do all
your work directly on the range objects:

With myDocument.Tables.Item(1).Cell(1, 1).Range
.InsertAfter(".") ' Inserts a period
:

End With
 
P

Phil

Thanks Helmut - exactly what I was looking for. That will be useful in the
future too.
Thanks for the hint Chuck and Jezebel - I think its a good idea to avoid
using the selection object to eliminate the unwanted movements.
 
H

Helmut Weber

Hi Phil,

you may adjust the values according to your needs.
However, my solution is limited to one-page tables!

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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