Solved

Set a range programmatically

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

679 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