Solved

Extend selectin to beginnig of document.

Posted on 2011-03-11
1
162 Views
Last Modified: 2012-05-11
Can someone tell me why this code does not keep selected the page that contains "secondary".  Should be easy to tell what I am tryign to do.  I want to find the page that contains "secondary" and then select that page and everything else before it.  Instead it is selecting all pages before the one that contains "secondary"
Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "secondary"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
ActiveDocument.Bookmarks("\Page").Range.Select
Selection.HomeKey wdStory, wdExtend



End Sub

Open in new window

0
Comment
Question by:BigWill5112
[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
1 Comment
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 500 total points
ID: 35113150
The code you show seems to act as if you clicked the mouse on the top character of the page "secondary" page, held down Shift, and then clicked at the bottom character of the page. If you press Ctrl-Shift-Home at this point, the selection is anchored at the top of the "secondary" page, not the bottom. I would suggest you just change line 21 to:

Selection.Start = 0

which explicitly changes the beginning of the selection and does not the affect the end.

Hope this helps,
pT72
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
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 shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

691 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