Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple VBA Range Question (Office/VBA 2003)

    Hi, all. Can someone explain to me (in clearer terms that found in the Help files) why I can use the Start and End properties when setting a range relative to the ActiveDocument.Range object, but I cannot do the same with an individual paragraph? In other words, why does it seem I must use two lines of code (Set myRange = overlylarge_range then myRange.SetRange fromHere, toHere) to set the desired range to part of a paragraph's range, but only one line would be needed to do the same with the ActivedDocument.Range (e.g. Set myRange = ActiveDocument.Range(fromHere, toHere).

    I realize I may simply be missing something, but I'd love to know what it might be!

    Thanks in advance...
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simple VBA Range Question (Office/VBA 2003)

    Range is - confusingly - both an property and a method in the Word object model (and an object, of course).

    Range(start, end) is a method of the Document object, but not of the Selection or Paragraph object. Both the Range method of the Document object and the SetRange method of the Range and Selection objects use start and end as absolute positions within the document, never as relative to another range.

    Example:

    Dim rng As Range
    Set rng = ActiveDocument.Range(100, 120) ' rng extends from character 101 to 120 in the document
    rng.SetRange 10, 15 ' rng extends from character 11 to 15 in the document

    The last instruction moves rng completely outside the original range.

  3. #3
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simple VBA Range Question (Office/VBA 2003)

    As ever, Hans, thanks for your wisdom and patience.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •