Solved

Populate UserForm List Box with Paragraph Text from MS Word Range

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

808 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