?
Solved

Extend selectin to beginnig of document.

Posted on 2011-03-11
1
Medium Priority
?
163 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

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 some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
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 …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 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