?
Solved

MsgBox listing all outline level 1 headings

Posted on 2008-11-02
3
Medium Priority
?
274 Views
Last Modified: 2012-05-05
Dear Experts:
Below macro lists all outline level 1 headings in a msgbox. Can this macro be expanded to list also the paragraph style name in the msgbox such as:

Section 3: List of Tables, Heading_List
Section 4: List of Figures, Heading_List
Section 5: 1 Introduction, Heading 1
Section 6: 2 Analysis, Heading 1
........
Section 12: Bibliography, Heading_End
Section 13: Appendix, Heading_End

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Sub ListOutlineLevel1ParaMsgBox()
Dim oPara As Paragraph
Dim strMsg As String
Dim rTmp As range ' a temporary range
Dim lTmp As Long  ' sections count
Dim l2Tmp As Long
 
Set rTmp = ActiveDocument.range
'Create start of message
strMsg = "Outline Level 1: " & vbCr
'Iterate through all paragraphs in active document
'If style has outline level 1, append to message
For Each oPara In ActiveDocument.Paragraphs
   If oPara.OutlineLevel = wdOutlineLevel1 Then
'   strMsg = "Outline level 1: " & vbCr
 
      With oPara.range
      rTmp.End = .End ' redefine the temporary range
      lTmp = rTmp.Sections.count ' count the sections
     
      
      'Append the heading number and text to the message
      strMsg = strMsg & " section: " & CStr(lTmp)
      strMsg = strMsg & "  " & .ListFormat.ListString & "  " & .Text _
      & "  "
      
      End With
      End If
Next oPara
MsgBox strMsg, vbOKOnly, "Summary Outline Level 1"
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 22862353
Hello AndreasHermle,

Keeping with what you have and making small changes ... try the following

Regards,
Chris
Sub ListOutlineLevel1ParaMsgBox()
Dim oPara As Paragraph
Dim strMsg As String
Dim rTmp As Range ' a temporary range
Dim lTmp As Long  ' sections count
Dim l2Tmp As Long
 
Set rTmp = ActiveDocument.Range
'Create start of message
strMsg = "Outline Level 1: " & vbCr
'Iterate through all paragraphs in active document
'If style has outline level 1, append to message
For Each oPara In ActiveDocument.Paragraphs
   If oPara.OutlineLevel = wdOutlineLevel1 Then
'   strMsg = "Outline level 1: " & vbCr
 
      With oPara.Range
      rTmp.End = .End ' redefine the temporary range
      lTmp = rTmp.Sections.Count ' count the sections
     
      
      'Append the heading number and text to the message
      strMsg = strMsg & " section: " & CStr(lTmp)
      strMsg = strMsg & "  " & .ListFormat.ListString & "  " & Left(.Text, Len(.Text) - 1) & _
      vbTab & oPara.Range.Font.Name & vbCrLf
      
      End With
      End If
Next oPara
MsgBox strMsg, vbOKOnly, "Summary Outline Level 1"
End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 22864791
Dear Chris,
thank you for your professional help. I slightly changed the code to "oPara.range.Style" instead of "oPara.range.Font.Name" (at the very end before "End With") . My requirment was actually to add the paragraph style name.  With your help I was able to change that myself.

Again, thank you for your professional help. Regards, Andreas
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22864892
Apologies for my oversight and well done to correct it yourself

Chris
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question