Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How to get non-overlapped page numbers?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
junya55  
View profile  
 More options Mar 28, 2:15 am
Newsgroups: microsoft.public.word.vba.beginners
From: junya55 <caf...@nifty.com>
Date: Fri, 27 Mar 2009 23:15:31 -0700 (PDT)
Local: Sat, Mar 28 2009 2:15 am
Subject: How to get non-overlapped page numbers?
Hi.

Please tell me how to get non-overlapped page numbers indicating
the pages, in wihch the found text exists in a document.

For example, when "steel" is shown twice in page 3 and three times in
page 5,
the following code returns the page numbers like, "page: 3, 3, 5, 5,
5, ".

Could you give me any advice to remove the overlapped page numbers
such
that the following code returns "page: 3, 5, " instead?

The code is shown below.
thanks in advance.

junya

........................................................................... .....
Sub page_search()

Dim myRange As Range
Dim pageNum As String

Set myRange = Selection.Range

Selection.HomeKey Unit:=wdStory

    With myRange.Find
        .Wrap = wdFindStop
        .MatchWholeWord = True
        .Execute FindText:="steel", Forward:=True
    End With

    Do While myRange.Find.Found = True
        pageNum = pageNum & _
                     myRange.Information(wdActiveEndPageNumber) _
                     & ", "
        myRange.Find.Execute
    Loop

    MSGBOX "page: " & pageNum
End Sub


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doug Robbins - Word MVP on news.microsoft.com  
View profile  
(1 user)  More options Mar 28, 4:56 am
Newsgroups: microsoft.public.word.vba.beginners
From: "Doug Robbins - Word MVP on news.microsoft.com" <d...@REMOVECAPSmvps.org>
Date: Sat, 28 Mar 2009 18:56:42 +1000
Local: Sat, Mar 28 2009 4:56 am
Subject: Re: How to get non-overlapped page numbers?
Use:

Dim myRange As Range
Dim pageNum As String
Dim Flag As Boolean
Flag = False
pageNum = ""
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
    Do While .Execute(FindText:="steel", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
        Set myRange = Selection.Range
        Selection.Collapse wdCollapseEnd
        If Len(pageNum) > 0 Then
            If Flag = False Then
                Flag = True
                If Val(pageNum) <>
myRange.Information(wdActiveEndPageNumber) Then
                    pageNum = pageNum & ", " &
myRange.Information(wdActiveEndPageNumber)
                End If
            ElseIf Val(Mid(pageNum, InStrRev(pageNum, ",") + 2)) <>
myRange.Information(wdActiveEndPageNumber) Then
                pageNum = pageNum & ", " &
myRange.Information(wdActiveEndPageNumber)
            End If
        Else
            pageNum = myRange.Information(wdActiveEndPageNumber)
        End If
    Loop
End With
MsgBox "page: " & pageNum

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"junya55" <caf...@nifty.com> wrote in message

news:0506b173-a190-4a1f-81e9-67ebd10b1af0@s38g2000prg.googlegroups.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
junya55  
View profile  
 More options Mar 28, 7:05 am
Newsgroups: microsoft.public.word.vba.beginners
From: junya55 <caf...@nifty.com>
Date: Sat, 28 Mar 2009 04:05:41 -0700 (PDT)
Local: Sat, Mar 28 2009 7:05 am
Subject: Re: How to get non-overlapped page numbers?
hi, Doug:

Thank you very much for your quick reply.
I really appreciate your help.

Val, InStrRev, and Mid are all new functions for me.
I now understand what you are doing after looking into
HELP files of VBE.

thanks a lot.

Junya


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
junya55  
View profile  
 More options Mar 30, 9:55 am
Newsgroups: microsoft.public.word.vba.beginners
From: junya55 <caf...@nifty.com>
Date: Mon, 30 Mar 2009 06:55:35 -0700 (PDT)
Local: Mon, Mar 30 2009 9:55 am
Subject: Re: How to get non-overlapped page numbers?
Hi, Doug:

Thank you for your advice.
I specially appreciate your IF lines for evaluating the pageNum
variable.

Because your code still returns overlapped page numbers sometimes,
I changed your code so that the code works O.K.

Your Original Code:

>             If Flag = False Then
>                 Flag = True
>                 If Val(pageNum) <>
> myRange.Information(wdActiveEndPageNumber) Then
>                     pageNum = pageNum & ", " &
> myRange.Information(wdActiveEndPageNumber)
>                 End If

in the above, I moved the line of "Flag = True" to the position
after the "If lines" as follows.

>             If Flag = False Then
>                 If Val(pageNum) <>
> myRange.Information(wdActiveEndPageNumber) Then
>                     pageNum = pageNum & ", " &
> myRange.Information(wdActiveEndPageNumber)

                  Flag = True

>                 End If

Flag should become "True" only after the second pageNum is added to
the first pageNum.

I think this works.
Thank you.

Junya


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Horowitz  
View profile  
(1 user)  More options Mar 30, 5:16 pm
Newsgroups: microsoft.public.word.vba.beginners
From: "David Horowitz" <da...@soundsidesoftware.com>
Date: Mon, 30 Mar 2009 17:16:56 -0400
Local: Mon, Mar 30 2009 5:16 pm
Subject: Re: How to get non-overlapped page numbers?
Junya,
I wanted to try my hand at this one too. Instead of using a boolean flag and
checking the text string, I stored the most recently added page number in an
integer.
I also maintained your original code's ability to search only from the
current cursor position.
I put comments to mark changes to your code.

Sub page_search()

Dim myRange As Range
Dim pageNum As String
Dim thisPage As Integer, lastPage As Integer ' new variables

Set myRange = Selection.Range

Selection.HomeKey Unit:=wdStory

    With myRange.Find
        .Wrap = wdFindStop
        .MatchWholeWord = True
        .Execute FindText:="steel", Forward:=True
    End With

    Do While myRange.Find.Found = True
        ' changes here
        thisPage = myRange.Information(wdActiveEndPageNumber)
        If thisPage <> lastPage Then
            pageNum = pageNum & _
                     thisPage _
                     & ", "
            lastPage = thisPage
        End If
        myRange.Find.Execute
    Loop

    ' remove the last comma and space
    If Len(pageNum) <> 0 Then pageNum = Left$(pageNum, Len(pageNum) - 2)
    MsgBox "page: " & pageNum
End Sub
--
David Horowitz
Lead Technologist
Soundside Inc.
www.soundside.biz

"junya55" <caf...@nifty.com> wrote in message

news:0506b173-a190-4a1f-81e9-67ebd10b1af0@s38g2000prg.googlegroups.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
junya55  
View profile  
 More options Mar 31, 8:12 am
Newsgroups: microsoft.public.word.vba.beginners
From: junya55 <caf...@nifty.com>
Date: Tue, 31 Mar 2009 05:12:12 -0700 (PDT)
Local: Tues, Mar 31 2009 8:12 am
Subject: Re: How to get non-overlapped page numbers?
Hi, David:

Thank you very much for sharing your idea.

your idea of using lastPage and thisPage strings
is very genius.

  lastPage = thisPage

i like the above way of thinking.

I am learning the thinking habit or thinking process of
programers, and your advice show me good one.

thanks a lot.

Junya


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Horowitz  
View profile  
 More options Mar 31, 12:26 pm
Newsgroups: microsoft.public.word.vba.beginners
From: "David Horowitz" <da...@soundsidesoftware.com>
Date: Tue, 31 Mar 2009 12:26:48 -0400
Local: Tues, Mar 31 2009 12:26 pm
Subject: Re: How to get non-overlapped page numbers?
That great Junya. There's no one right way to do things. I always learn from
seeing the multiple ways people would go about things and going from there.
You've learned all new things between Doug's use of Val, InstrRev, and Mid,
booleans, text processing, and I added on Left and using a variable to store
the most recent page number.
Happy coding!
Dave
--
David Horowitz
Lead Technologist
Soundside Inc.
www.soundside.biz
"junya55" <caf...@nifty.com> wrote in message

news:434d29b6-9da6-4ed3-b869-035b55852fda@s1g2000prd.googlegroups.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google