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: Thu, 2 Oct 2008 23:25:50 -0700 (PDT),    group: microsoft.public.word.vba.general        back       


List Text that uses built-in style Heading 1 in a MsgBox   
Dear Experts:

Below macro (courtesy of Lene Fredborg) lists the text that uses built-
in style Heading 1 in a new document.

I would like the macro changed with the following feature:

(1) list the text in a msgbox, not in a new document
(2) the outline numbering should also be listed (such as 1
Introduction, 2 Analysis, 3 Summary etc.)

I hope this is feasible. Thank you very much in advance for your
help.

Regards, Andreas



Sub ListHeading1Paras()
    Dim oPara As Paragraph
    Dim oDocH1 As Document
    Dim oDoc As Document
    Set oDoc = ActiveDocument
    Set oDocH1 = Documents.Add
    'Make sure oDocH1 starts empty and with style Normal
    With oDocH1
        .range = ""
        .Paragraphs(1).Style = oDoc.Styles(wdStyleNormal)
    End With
    'Iterate through all paragraphs in active document
    'If style is Heading 1, insert text in oDocH1
    For Each oPara In oDoc.Paragraphs
        If oPara.Style = oDoc.Styles(wdStyleHeading1) Then
            oDocH1.range.InsertAfter oPara.range.Text
        End If
    Next oPara
    'Clean up
    Set oDoc = Nothing
    Set oDocH1 = Nothing
End Sub
date: Thu, 2 Oct 2008 23:25:50 -0700 (PDT)   author:   andreas

RE: List Text that uses built-in style Heading 1 in a MsgBox   
I think the following version will do what you want:

Sub ListHeading1Paras_MSG()
    Dim oPara As Paragraph
    Dim strMsg As String
    
    'Create start of message
    strMsg = "The document contains the following Heading 1 text:" & vbCr & 
vbCr
    
    'Iterate through all paragraphs in active document
    'If style is Heading 1, append to message
    For Each oPara In ActiveDocument.Paragraphs
        If oPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
            With oPara.Range
                'Append the heading number and text to the message
                strMsg = strMsg & .ListFormat.ListString & " " & .Text
            End With
        End If
    Next oPara
    
    'Show message
    MsgBox strMsg, vbOKOnly, "Heading 1 Text"
    
End Sub

-- 
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"andreas" wrote:

> Dear Experts:
> 
> Below macro (courtesy of Lene Fredborg) lists the text that uses built-
> in style Heading 1 in a new document.
> 
> I would like the macro changed with the following feature:
> 
> (1) list the text in a msgbox, not in a new document
> (2) the outline numbering should also be listed (such as 1
> Introduction, 2 Analysis, 3 Summary etc.)
> 
> I hope this is feasible. Thank you very much in advance for your
> help.
> 
> Regards, Andreas
> 
> 
> 
> Sub ListHeading1Paras()
>     Dim oPara As Paragraph
>     Dim oDocH1 As Document
>     Dim oDoc As Document
>     Set oDoc = ActiveDocument
>     Set oDocH1 = Documents.Add
>     'Make sure oDocH1 starts empty and with style Normal
>     With oDocH1
>         .range = ""
>         .Paragraphs(1).Style = oDoc.Styles(wdStyleNormal)
>     End With
>     'Iterate through all paragraphs in active document
>     'If style is Heading 1, insert text in oDocH1
>     For Each oPara In oDoc.Paragraphs
>         If oPara.Style = oDoc.Styles(wdStyleHeading1) Then
>             oDocH1.range.InsertAfter oPara.range.Text
>         End If
>     Next oPara
>     'Clean up
>     Set oDoc = Nothing
>     Set oDocH1 = Nothing
> End Sub
>
date: Fri, 3 Oct 2008 03:38:01 -0700   author:   Lene Fredborg

Re: List Text that uses built-in style Heading 1 in a MsgBox   
On Oct 3, 12:38 pm, Lene Fredborg 
wrote:
> I think the following version will do what you want:
>
> Sub ListHeading1Paras_MSG()
>     Dim oPara As Paragraph
>     Dim strMsg As String
>
>     'Create start of message
>     strMsg = "The document contains the following Heading 1 text:" & vbCr &
> vbCr
>
>     'Iterate through all paragraphs in active document
>     'If style is Heading 1, append to message
>     For Each oPara In ActiveDocument.Paragraphs
>         If oPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
>             With oPara.Range
>                 'Append the heading number and text to the message
>                 strMsg = strMsg & .ListFormat.ListString & " " & .Text
>             End With
>         End If
>     Next oPara
>
>     'Show message
>     MsgBox strMsg, vbOKOnly, "Heading 1 Text"
>
> End Sub
>
> --
> Regards
> Lene Fredborg - Microsoft MVP (Word)
> DocTools - Denmarkwww.thedoctools.com
> Document automation - add-ins, macros and templates for Microsoft Word
>
>
>
> "andreas" wrote:
> > Dear Experts:
>
> > Below macro (courtesy of Lene Fredborg) lists the text that uses built-
> > in style Heading 1 in a new document.
>
> > I would like the macro changed with the following feature:
>
> > (1) list the text in a msgbox, not in a new document
> > (2) the outline numbering should also be listed (such as 1
> > Introduction, 2 Analysis, 3 Summary etc.)
>
> > I hope this is feasible. Thank you very much in advance for your
> > help.
>
> > Regards, Andreas
>
> > Sub ListHeading1Paras()
> >     Dim oPara As Paragraph
> >     Dim oDocH1 As Document
> >     Dim oDoc As Document
> >     Set oDoc = ActiveDocument
> >     Set oDocH1 = Documents.Add
> >     'Make sure oDocH1 starts empty and with style Normal
> >     With oDocH1
> >         .range = ""
> >         .Paragraphs(1).Style = oDoc.Styles(wdStyleNormal)
> >     End With
> >     'Iterate through all paragraphs in active document
> >     'If style is Heading 1, insert text in oDocH1
> >     For Each oPara In oDoc.Paragraphs
> >         If oPara.Style = oDoc.Styles(wdStyleHeading1) Then
> >             oDocH1.range.InsertAfter oPara.range.Text
> >         End If
> >     Next oPara
> >     'Clean up
> >     Set oDoc = Nothing
> >     Set oDocH1 = Nothing
> > End Sub- Hide quoted text -
>
> - Show quoted text -

Dear Lene,

very nice piece of coding. I just tried it out. Exactly what I wanted.
Thank you very much for your professional help. Regards,  Andreas
date: Fri, 3 Oct 2008 06:32:40 -0700 (PDT)   author:   andreas

Re: List Text that uses built-in style Heading 1 in a MsgBox   
You are welcome. I am glad i could help.

-- 
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"andreas" wrote:

> On Oct 3, 12:38 pm, Lene Fredborg 
> wrote:
> > I think the following version will do what you want:
> >
> > Sub ListHeading1Paras_MSG()
> >     Dim oPara As Paragraph
> >     Dim strMsg As String
> >
> >     'Create start of message
> >     strMsg = "The document contains the following Heading 1 text:" & vbCr &
> > vbCr
> >
> >     'Iterate through all paragraphs in active document
> >     'If style is Heading 1, append to message
> >     For Each oPara In ActiveDocument.Paragraphs
> >         If oPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
> >             With oPara.Range
> >                 'Append the heading number and text to the message
> >                 strMsg = strMsg & .ListFormat.ListString & " " & .Text
> >             End With
> >         End If
> >     Next oPara
> >
> >     'Show message
> >     MsgBox strMsg, vbOKOnly, "Heading 1 Text"
> >
> > End Sub
> >
> > --
> > Regards
> > Lene Fredborg - Microsoft MVP (Word)
> > DocTools - Denmarkwww.thedoctools.com
> > Document automation - add-ins, macros and templates for Microsoft Word
> >
> >
> >
> > "andreas" wrote:
> > > Dear Experts:
> >
> > > Below macro (courtesy of Lene Fredborg) lists the text that uses built-
> > > in style Heading 1 in a new document.
> >
> > > I would like the macro changed with the following feature:
> >
> > > (1) list the text in a msgbox, not in a new document
> > > (2) the outline numbering should also be listed (such as 1
> > > Introduction, 2 Analysis, 3 Summary etc.)
> >
> > > I hope this is feasible. Thank you very much in advance for your
> > > help.
> >
> > > Regards, Andreas
> >
> > > Sub ListHeading1Paras()
> > >     Dim oPara As Paragraph
> > >     Dim oDocH1 As Document
> > >     Dim oDoc As Document
> > >     Set oDoc = ActiveDocument
> > >     Set oDocH1 = Documents.Add
> > >     'Make sure oDocH1 starts empty and with style Normal
> > >     With oDocH1
> > >         .range = ""
> > >         .Paragraphs(1).Style = oDoc.Styles(wdStyleNormal)
> > >     End With
> > >     'Iterate through all paragraphs in active document
> > >     'If style is Heading 1, insert text in oDocH1
> > >     For Each oPara In oDoc.Paragraphs
> > >         If oPara.Style = oDoc.Styles(wdStyleHeading1) Then
> > >             oDocH1.range.InsertAfter oPara.range.Text
> > >         End If
> > >     Next oPara
> > >     'Clean up
> > >     Set oDoc = Nothing
> > >     Set oDocH1 = Nothing
> > > End Sub- Hide quoted text -
> >
> > - Show quoted text -
> 
> Dear Lene,
> 
> very nice piece of coding. I just tried it out. Exactly what I wanted.
> Thank you very much for your professional help. Regards,  Andreas
>
date: Fri, 3 Oct 2008 07:44:03 -0700   author:   Lene Fredborg

Google
 
Web ureader.com


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