VBA word range operations

When using or adjusting ranges, some ranges behave differently than other ranges. For instance,

ActiveDocument.Range(10, 20).Select
ActiveDocument.Tables(2).Cell(1, 1).Range(10, 20).Select

The first line, if OK, and works as expected. The second line causes an error in the Range statement, although it seems that two lines should be identical for it.

What is the difference?

+3
source share
1 answer

Rangeon Cellis a property, not a method - it returns the range of the document represented by the cell.

This means that you cannot add arguments such as (10,20).

The following is equivalent:

 Dim rangeStart As Integer
 rangeStart = ActiveDocument.Tables(2).Cell(1, 1).Range.Start
 ActiveDocument.Range(rangeStart + 10, rangeStart + 20).Select
+3
source

Source: https://habr.com/ru/post/1763085/


All Articles