Print contents of listbox

D

dsc

This has probably been answered a million times already, but...

How do you print the contents of a listbox and send the contents to a file?

Thanks to anybody who has the patience.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi DSC,

See the article “How to find out which Items are selected in a Multi-Select
ListBox” at:

http://www.mvps.org/word/FAQs/Userforms/GetMultiSelectValues.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

dsc

Thanks for the reply.

I guess I'm just iggernunt, but I don't see how that relates to printing the
contents of a listbox.

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi dsc,

It was intended to give you an idea of how to access the items in a list
box.

Where is the list box? On a userform?

The following code will populate a listbox and then it will create a list in
the activedocument of the items in the listbox and print out the active
document

Dim i As Long
For i = 1 To 10
ListBox1.AddItem "Item " & i
Next i
For i = 1 To ListBox1.ListCount
ListBox1.ListIndex = i - 1
ActiveDocument.Range.InsertAfter ListBox1.Value & vbCr
Next i
ActiveDocument.PrintOut

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

dsc

Hello, Doug,

You're a great help as always.
It was intended to give you an idea of how to access the items in a list
box.

Two dum too git thet, sorry.

Yes, the listbox is on a userform.
The following code will populate a listbox and then it will create a list in
the activedocument of the items in the listbox and print out the active
document

Sure does, thanks a lot.

Only one thing: the list box has three columns, and the code as written is
only pulling out the first column. Is there a way to get the data from the
other two columns and print it in three columns?

And after that, I'd like the Internet moved a couple of inches to the
southeast, please.

Sorry to keep asking, but I couldn't find anything on this on the Net.

Thanks again,

dsc
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi DSC,

Try this version:

Dim i As Long, j As Long
Dim NewArray() As Variant
ListBox1.ColumnCount = 3
ReDim NewArray(10, 3)
For j = 0 To 2
For i = 0 To 9
NewArray(i, j) = "Item " & Chr(j + 65) & i + 1
Next i
Next j
ListBox1.List() = NewArray
For i = 1 To ListBox1.ListCount - 1
For j = 1 To 2
ListBox1.BoundColumn = j
ListBox1.ListIndex = i - 1
ActiveDocument.Range.InsertAfter ListBox1.Value & vbTab
Next j
ListBox1.BoundColumn = j
ActiveDocument.Range.InsertAfter ListBox1.Value & vbCr
Next i

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

dsc

Perfecto.

Thanks for your assistance and patience.

Just to make the printout prettier, I added this:

Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=3, _
NumRows:=298, Format:=wdTableFormatNone, ApplyBorders:=True,
ApplyShading _
:=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True, _
ApplyLastRow:=False, ApplyFirstColumn:=True, ApplyLastColumn:=False,
_
AutoFit:=True, AutoFitBehavior:=wdAutoFitFixed
Selection.MoveUp Unit:=wdLine, Count:=1

Best regards,

dsc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top