Search Page Question

M

Mable

Okay, I'm putting together a macro in VB, and I've come
across a small problem.

I want to search each individual page for a character in
white, dump that character to a variable, and the program
continues depending upon the variable. my problem is that
I cannot for the life of me figure out how to specify that
VB should only search one page at a time, find the white
character, process it, and THEN search the next page.

Anyone know what I can do about this?
 
M

Mable

Not that I know of. I checked the auto-help thing in
VB.NET and the MSDN library, and it's not. Any other ideas?
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < (e-mail address removed) > écrivait :

|| Isn't PAGE a property/method of RANGE?
||

No.

Dealing with pages in VB can be cumbersome.

It is one of the instances where you often have to resort to using the
Selection object, depending on how you are cycling through the pages.

Once you have the selection on the page you want to select, try:

ActiveDocument.Bookmarks("\Page").Range.Delete
or

ActiveDocument.Bookmarks("\Page").Range.Copy
or
ActiveDocument.Bookmarks("\Page").Range.Select
etc.

Or, if you can define a range object on each page, try:

'_______________________________________
Sub Test()

Dim MyRge As Range

Set MyRge = Selection.Range

MyRge.Bookmarks("\Page").Range.Select

End Sub
'_______________________________________

Another example:

'_______________________________________
Sub CharactersPerPAge()

Dim MyRge As Range

Set MyRge = Selection.Range

With MyRge

..Collapse
..Select
MsgBox .Bookmarks("\Page").Range.Characters.Count _
& " characters on page " & Selection.Information(wdActiveEndPageNumber)
_
& ".", vbInformation, "Characters per page"

End With

End Sub
'_______________________________________

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

Jean-Guy Marcil

Bonjour,

Dans son message, < Mable > écrivait :
In this message, < Mable > wrote:

|| Okay, I'm putting together a macro in VB, and I've come
|| across a small problem.
||
|| I want to search each individual page for a character in
|| white, dump that character to a variable, and the program
|| continues depending upon the variable. my problem is that
|| I cannot for the life of me figure out how to specify that
|| VB should only search one page at a time, find the white
|| character, process it, and THEN search the next page.
||

Go to the first page;
Select the first page (See my other post in the same thread),
Define it as a range,
Do your stuff with this range (Find character, define variable, etc.),
Collapse to the end of the range,
You will automatically end up at the beginning of the next page,
Select that page,
Redefine the range,
etc.,
All the while, check that the page you are on is not the last page, if it
is, dot try to go to a next page.

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

Mable

This would work, but I need something automated, as this
macro is being designed to sort out documents of upwards
of 200 pages. I need some way to either a) define a page
or b) make the FIND command search for individual results,
report them for processing, and then go find the next
result; as opposed to the current method of finding
everything at once.

Thanks, though.
 
M

Mable

All of a sudden (as is usual with Microsoft programs, I'm
learning) the FIND command is now seeking each object
individually. This removes my need for the nonexistant
page property. I thank you for your help.

-Mable
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Mable > écrivait :
In this message, < Mable > wrote:

| This would work, but I need something automated, as this
| macro is being designed to sort out documents of upwards
| of 200 pages. I need some way to either a) define a page
| or b) make the FIND command search for individual results,
| report them for processing, and then go find the next
| result; as opposed to the current method of finding
| everything at once.
|

Ahhhh!
This has nothing to do with pages! ;-)

You need someting like this:
'_______________________________________
Sub ProcessEachFind()

Selection.HomeKey wdStory

With Selection.Find
.ClearFormatting
.Text = "apple"
.Forward = True
.Wrap = wdFindContinue
Do While .Execute
MsgBox "Found one"
'Do your stuff here
Loop
End With

End Sub
'_______________________________________

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

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