Selecting a page

J

Jack

Would someone be able to tell me how to select a range on
a specific page in a word document. For example I am using
one of the following to select text from a word document:

1) Set Vendorname = ActiveDocument.Range(Start:=108,
End:=149)

2) Set VendorLine1 = appWrd.ActiveDocument.Range
(Start:=205, End:=206)
VendorLine1.End = VendorLine1.Paragraphs(1).Range.End
VendorLine1.MoveEnd Unit:=wdCharacter, Count:=-1


However, I am not able to select this on anything but the
first page. How can I use VBA to say I want this from
another page?

Thanks!!
 
E

Ed

Jack: What I wound up doing one time was using
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, _
Count:=PgNo
You can set your "PgNo" variable with a UserForm or Input Box. Then use
PgNo+1 to take you to the first character position of the next page.

With this (keep in mind I haven't done this personally), you could set a
bookmark("Mark1", let's say) at the first position, and set another bookmark
("Mark2") at the second position. Now set a range between the two
bookmarks:
Set rng = ActiveDocument.Range _
(Start:= ActiveDocument.Bookmarks("Mark1").End, _
End:= ActiveDocument.Bookmarks("Mark2").Start)

Hope it works for you.
Ed
 
J

Jack

Thanks, I got the part about using the "PgNo", but now
how do I make a bookmark on the page I select? Sorry but
I am new to Word VBA.
 
E

Ed

ActiveDocument.Bookmarks.Add Name:="Mark1"

Two things to help you learn more:
(1) The F1 key: brings up the Help files, which often have code examples.
As you're typing in code, set the cursor in the name of the object,
property, or method you want to learn more about and press F1. It will
bring up the Help topic for that item, and usually give you associated items
as well.
(2) Google search the newsgroups. Just about every question has been
answered there before. (Where do you think I get half my code? 8>) )

HTH
Ed
 
E

Ed

Wow! A bookmark that ALREADY contains the current page?!? I wish I had
read a bit more a year ago! Thank you, Christian, for helping both Jack and
me!

Ed
 
J

Jack

Yes,
Thanks!!

But how ,specificaly, would I add a bookmark on say Page 5
that starts say at character 180 and goes to 200?
 
J

Jean-Guy Marcil

Jack was telling us:
Jack nous racontait que :
Yes,
Thanks!!

But how ,specificaly, would I add a bookmark on say Page 5
that starts say at character 180 and goes to 200?

Do you mean (1) the 180th charcter in the document (Which happens to be on
page 5) or (2) the 180th character on page 5?

(1)
'_______________________________________
Sub DocBookMark()

Dim MyRange As Range

With ActiveDocument
Set MyRange = .Range(Start:=.Characters(180).Start, _
End:=.Characters(200).End)
.Bookmarks.Add Name:="Test", Range:=MyRange
End With

End Sub
'_______________________________________

or
(2)
'_______________________________________
Sub PageBookMark()

Dim MyRange As Range
Dim CurrentRange As Range

'To save user selection
Set CurrentRange = Selection.Range
Selection.GoTo wdGoToPage, wdGoToAbsolute, 5

Set MyRange = Selection.Bookmarks("\page").Range

With MyRange
If .Characters.Count > 198 Then
.MoveEnd wdCharacter, 199 - .Characters.Count
.MoveStart wdCharacter, 179
.Bookmarks.Add Name:="Test", Range:=MyRange
Else
MsgBox "Too few charcters on target page to " _
& "create bookmark.", vbExclamation, "Cancelled"
End If
End With

'Replace user original selection
CurrentRange.Select

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
R

Renjith

Hi,
Does any body has idea how to save Individual Pages at random from an MS
Word file without any changes in the Formatting. Also, how can I get the Font
Type and Style for Bullets and Numbering on a particular file. Can someone
help me?
 
R

Renjith

Hi there,

I have tried this. It is capturing the whole page, but the problem is that
if my document contains a Section Break towards the end of the page, then it
becomes a Page Break. how can I solve this probelm?
Also I would like to get the font type and size of the Bullets in a
particular doc file.

Thanks and Regards,
Renjith R Nair
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top