Solved

Set a range programmatically

Posted on 2013-05-15
4
281 Views
Last Modified: 2013-05-15
Dear Experts:

I would like to set a range in the Active Document that ...

spans from the second paragraph of the first page till the end of the penultimate paragraph of the page where the first manual page break (Strg + Enter) occurs.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39167994
Hi Andreas,

Should the range include or exclude the second paragraph?  Also is the penultimate paragraph on the page that is terminated by the page break, or on the following one?
0
 

Author Comment

by:AndreasHermle
ID: 39168027
Hi Graham,

thank you very much for your swift support:

... the range is to include the second paragraph

... the penultimate paragraph is on the page that is terminated by the manual page break


Andreas
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39168158
Here it is as a function
Function GetRange(doc As Word.Document) As Range
    Dim rng As Range
    Dim rng1 As Range
    
    Set rng = doc.Range
    With rng.Find
        .Text = "^m"
        If .Execute Then
            Set rng1 = rng.Duplicate
        End If
    End With
    rng1.Move wdParagraph, -2
    rng1.Expand wdParagraph
    rng1.Collapse wdCollapseStart
    
    Set rng = doc.Paragraphs.First.Range
    rng.Collapse wdCollapseEnd
    rng.End = rng1.Start
    Set GetRange = rng
End Function

Open in new window

You can use it like this:
GetRange(ActiveDocument).Select

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 39168302
Graham,

as always, I am truly impressed with your expertise.

Thank you very much for your swift and professional support.

Regards, Andreas
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Does Mac Word 2016 have collapsable regions? 8 81
Word 2016 Installation Problem on Terminal Server 9 73
Sources to create infographic resume 2 73
Paragraph formating? 2 40
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question