Solved

Populate UserForm List Box with Paragraph Text from MS Word Range

Posted on 2012-12-27
2
629 Views
Last Modified: 2012-12-28
Hi All

Seasons Greetings :-D

I am struggling with something that I thought would be close to simple...  Populate a userform listbox with text from a specified range in a document.  Each entry should be a single paragraph...  (ideally I'd also like the paragraph number to show up; I'm using a list style).

Private Sub UserForm_Initialize()  '  <<<< code in user form (UF)
Dim iRng As Range  ' this is defined by a bookmark
Dim parra As Paragraph
Dim pText As String

With ActiveDocument
Set iRng = ActiveDocument.Bookmarks("iTxt").Range   ' works, the range is selected
iRng.Select
For Each parra In iRng   ' <<<<  No matter what I do here the code fails with an unhelpful message
pText = parra.Range.Text
 RefListBox.AddItem (pText)

Next parra
 
End With
End Sub

Open in new window


There is a sub to call this...

Sub myUF()
UF.Show

End Sub

Open in new window


The error message is:
Run-time error '438'
Object doesn't support this property or method

When I try to debug the line UF.show is higlighted...
0
Comment
Question by:DrTribos
2 Comments
 
LVL 14

Accepted Solution

by:
Faustulus earned 500 total points
ID: 38726142
The For .. Each loop sorts through a collection, to be precise, the collection of paragraphs in iRng. It can't sort through iRng because iRng isn't a collection. Therefore, please try
For Each parra In iRng.Paragraphs

Open in new window

0
 
LVL 14

Author Closing Comment

by:DrTribos
ID: 38726269
Thank you for the solution (which has been driving me nuts) and your explanation which I hope to apply in the future!

d
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now