Solved

Populate UserForm List Box with Paragraph Text from MS Word Range

Posted on 2012-12-27
2
627 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now