Share via

selection.homekey

Anonymous
2011-05-04T20:05:02+00:00

Could someone please explain to me how else I can execute the following two bits of script without using 'Selection' method as it causes (I think) the screen to flicker as part of my lengthy code

1)

    Selection.HomeKey Unit:=wdStory, Extend:=wdMove

    Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdMove

    Selection.EndKey Unit:=wdStory, Extend:=wdExtend

    Selection.Delete

    Selection.TypeParagraph

The above code deletes the content of the document apart from the first table, which appears right at the start of the document (which is the title of my document and is placed on it's own in the first table).  The final TypeParagraph allows for a new table to be added without joining it to the 1st table.

  1.    

    Selection.EndKey Unit:=wdStory

    Selection.TypeParagraph

This code I use to goto the end of the document and again, I add a TypeParagraph to ensure that the new table I add is not joined to an existing table.

Basically, can anybody explain the various range options and features to me???

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-05-04T22:39:15+00:00

A "line" is an elusive unit in Word VBA since a Word document is not stored as a collection of lines but as a collection of paragraphs. To get a grip on lines, you need the Selection object...

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-05-04T21:51:01+00:00

    Thanks for the notification, I have reposted in the correct forum.

    I have the Application.ScreenUpdating set to False, which works for the majority of the code, however, there is still a flicker and when reviewing my code, the only part that uses .selection is the code in my original post.

    As always, thanks for your time Hans.

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2011-05-04T20:36:04+00:00

    You have posted this in the Access forum but it is a question about Word.

    To avoid screen flicker, you can add a line

    Application.ScreenUpdating = False

    at the beginning of your code, and

    Application.ScreenUpdating = True

    at the end (the latter is not strictly necessary)

    Was this answer helpful?

    0 comments No comments