Solved

Set a range programmatically

Posted on 2013-05-15
4
251 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
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…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now