View Single Post
 
Old 04-30-2018, 05:27 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

What do you mean that a TOC has no style? Every paragraph in document has a style.

You are not putting anything in an array. Your functions returns a string value not an array.

You might try:

Code:
Sub Test()
  MsgBox funGetHeadingFromStyle("Heading 1")
End Sub
Public Function funGetHeadingFromStyle(ByVal strStyleToFind As String) As String
Dim oPar As Paragraph
Dim lngIndex As Long
  For Each oPar In ActiveDocument.Paragraphs
    If oPar.Style = strStyleToFind Then
    If lngIndex = 0 Then
      funGetHeadingFromStyle = Left(oPar.Range.Text, Len(oPar.Range.Text) - 1)
    Else
      funGetHeadingFromStyle = funGetHeadingFromStyle & ", " & Left(oPar.Range.Text, Len(oPar.Range.Text) - 1)
    End If
    lngIndex = lngIndex + 1
    End If
  Next
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote