Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select previous x pages 1

Status
Not open for further replies.

RustyAfro

Programmer
Jan 12, 2005
332
US
Hi everyone,

I thought this would be easy, but I cannot find anything on how to do it.

I have a process that pastes x pages, does things, pastes x pages, does things, etc.

After the paste of x pages, the cursor is at the bottom of the last page.

I need to select (highlight) the previous x pages that just pasted. I was hoping the below code would work, but all it does is move the cursor to the top of the first set of pages that just pasted. If it would move/select that "range" it just moved through to get to the top of first of x pages just pasted, it would be perfect.

Code:
'Note, this code is in vb.net, but if you have a vba solution, I can mod it into vb.net.
 Dim MergeRange As Range
 MergeRange = app.Selection.GoTo(WdGoToItem.wdGoToPage, which:=WdGoToDirection.wdGoToPrevious, Name:=(k + (NumOfPagesInDoc - 1)))

I want to do this because the process I run on each set of pages starts fast then gets progressively slower because it is looking at the entire document.
 
Word can do just about anything navigationally. You simply have to figure out how to tell it.
I need to select (highlight) the previous x pages that just pasted. I was hoping the below code would work, but all it does is move the cursor to the top of the first set of pages that just pasted. If it would move/select that "range" it just moved through to get to the top of first of x pages just pasted, it would be perfect.

1. It may help by inderstanding why you want to select the pages just pasted. Why are you doing that?

2. However, it could easily be done by placing a bookmark just before the paste. The selection will be at the end. Make a Selection from the end back to the bookmark.

3. It would in fact be much easier to make that area an actual range. This is much better than using Selection.

Gerry
 
Fumei, Thank you for responding. I ended up using a bookmark solution. What I do is after pasting the page(s), I go to the bookmark (which is the pages selected), then I do my process to what is selected, delete the bookmark, paste again, and so forth. Works great =)
 
Still using the Selection object. Range object is better, but hey, if it works for you, great.

Gerry
 
Hi Fumei,

Could you explain how to make a range? I don't understand it when I thought I did.
 
The main advatnage to using a Range rather than a Selection is a Range is not displayed, Selections of course are.

You state you used the bookmark solution. Please describe exactly what you did.

You may want to consider making ALL your pastes bookmarks. That way you could not only retreive them after the paste, but you could retrieve them individually anytime.

Exactly how are you doing the paste? If it uses Selection.Paste, then:
Code:
Selection.Paste
ActiveDocument.Bookmarks.Add Name:="Paste1", _
   Range:=Selection.Range
.....do the next paste
ActiveDocument.Bookmarks.Add Name:="Paste2", _
   Range:=Selection.Range
...do the next paste
ActiveDocument.Bookmarks.Add Name:="Paste3", _
   Range:=Selection.Range

Now, when you want to do any action on any specific "paste", you can use a Range. Say to do something with the first paste - bookmarked as "Paste1".
Code:
Dim oRange As Word.Range
Set oRange = ActiveDocument.Boomarks("Paste1").Range
oRange.Font.Bold = True [COLOR=red]' bolds the entire range[/color red]

[COLOR=red]' Use search through the range[/color red]
With oRange.Find
  .Text = "Blah blah"
  .Replacement = "Bluu bluu"
 etc etc
End With

There is a lot you can do with a Range.

If you use a Set to make a Range object (or any other object), do not forget to destroy the object when you are done with it.
Code:
Set oRange = Nothing

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top