Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 26 Feb 2008 06:02:09 -0800 (PST),    group: microsoft.public.word.vba.beginners        back       


How I can select all data between two headers ?   
Hi All,

Does anyone know is it possible to select all data between two
header ? I can find header # 1 by running followed code:

Selection.Find.ClearFormatting
Selection.GoTo what:=wdGoToHeading, which:=wdGoToAbsolute, Count:=1,
Name:=""

Thanks!
date: Tue, 26 Feb 2008 06:02:09 -0800 (PST)   author:   Jim

Re: How I can select all data between two headers ?   
What are you trying to accomplish? Why do you need to select the text?

If you explained what you are trying to do, someone might be able to suggest 
an alternative, and potentially better, approach.

-- 
Stefan Blom
Microsoft Word MVP


"Jim" wrote in message
news:11f4b2fc-d8ef-4de1-8233-d12fbc9e6e50@t66g2000hsf.googlegroups.com...
> Hi All,
>
> Does anyone know is it possible to select all data between two
> header ? I can find header # 1 by running followed code:
>
> Selection.Find.ClearFormatting
> Selection.GoTo what:=wdGoToHeading, which:=wdGoToAbsolute, Count:=1,
> Name:=""
>
> Thanks!
date: Wed, 27 Feb 2008 11:57:36 +0100   author:   Stefan Blom

Re: How I can select all data between two headers ?   
I agree.  Please describe precisely what you are trying to do.  First of all,
"all data between two header " is not accurate, at least in respect to your
code.

Header is a very specific term in Word.

I believe you mean heading, not header.

Not only  that, but wdGoToHeading will only go to a paragraph that has a
Heading style attached to it.  If you are using a different style for your
headings, then it will not work.

In any case, yes, certainly, it can be done.  You can select - and do you
REALLY mean Select???? - the text between, well, anything, including headings.
Here are some hints.

1.  use Range, not Selection.
2.  use a loop on the Execute of the Range.Find
3.  use a Collapse on the Found of the range.Find
4.  use two variables to set the values of the END of the Found, and the
START of the next
5.  grab the range - between the headings - using those values.  I.e. the END
of the Found heading, and the START of the next one.

Voila, the text between headings.

Jim wrote:
>Hi All,
>
>Does anyone know is it possible to select all data between two
>header ? I can find header # 1 by running followed code:
>
>Selection.Find.ClearFormatting
>Selection.GoTo what:=wdGoToHeading, which:=wdGoToAbsolute, Count:=1,
>Name:=""
>
>Thanks!

-- 
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200802/1
date: Wed, 27 Feb 2008 20:43:57 GMT   author:   fumei via OfficeKB.com u37563@uwe

Re: How I can select all data between two headers ?   
On Feb 27, 1:02 am, Jim  wrote:
> Hi All,
>
> Does anyone know is it possible to select all data between two
> header ? I can find header # 1 by running followed code:
>
> Selection.Find.ClearFormatting
> Selection.GoTo what:=wdGoToHeading, which:=wdGoToAbsolute, Count:=1,> Name:=""
>
> Thanks!

Assuming you mean between paragaphs formatted with the same paragraph
style eg "Heading 1"
The code below will do it.


Note: I assume by header you mean some sort of heading in the text.  I
further assume the heading is formatted using a paragraph style called
"Heading 1".  In the word context header can also refer to the
paragraph style called "Header" but usually refers to the text that
appears at the top of each page as distinct from the the "Footer" also
a defalut word style but also meaning the bit that appears at the
bottom of every page, ad defined using "View Header/Footer".

 I hope this is more helpfule to get you thinking.

Cheers!
TonyS.



    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Heading 1")
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    'moves the selection off the found heading 1 style
    'towards the end of the document
    Selection.EndKey Unit:=wdLine
    Selection.MoveRight Unit:=wdCharacter, Count:=1


    ' will extend the selection from here to wherever
    ' the next find takes us
    Selection.Extend

    'find the neaxt heading
    Selection.Find.Execute


    'move the end of the selection to before the start of this
selection/heading style
    '   Selection.HomeKey Unit:=wdLine, Extend:=True
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=True
    Selection.HomeKey Unit:=wdLine, Extend:=True

    Selection.ExtendMode = False

    X = Selection.Text

    'set up to before the previous find in case we want to recurse
this operation
    Selection.Collapse wdCollapseEnd
date: Sun, 23 Mar 2008 19:05:36 -0700 (PDT)   author:   Tony Strazzeri

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us