print from listbox

M

misscrf

I am so excited! I have automated charts in excel, so that the user ca
open to a menu worksheet, refresh all of the chart's data (wit
parameter) and preview and print them.

I am learning vb as I go, and I don't think I am do TOO bad. Anyway,
wanted to make a user form in the vb code to have a list box. I woul
make a 4th button on this menu sheet, so that the user can choose t
print just 1 or more chart, rather than all of them.

I created the list box, and populated it list. This is a multiselec
with checkboxes.

Private Sub UserForm_Initialize()
'The 1st list box contains 3 data columns
ListBox1.ColumnCount = 7

'Load integer values into first column of MyArray


'Load columns 2 and three of MyArray
MyArray(0, 0) = "Domestic Long Distance"
MyArray(1, 0) = "Toll Free"
MyArray(2, 0) = "Directory Assistance"
MyArray(3, 0) = "Local"
MyArray(4, 0) = "International"
MyArray(5, 0) = "Calling Cards"
MyArray(6, 0) = "Usage Type"


'Load data into ListBox1
ListBox1.List() = MyArray

End Sub


Now I will have a command button on the user form to print the selecte
charts. My question is, how do I do that?

I have looked for the code, but I am not finding a direct answer.
figure I need to declare each row value = to the chart that I have, an
then for each value selected print that chart. Right? :confused:

Any help on this code would be great!
Thanks all.

This is fun. I want to be a vb expert! hehehehe
misscrf

Management is doing things right, leadership is doing the right thing
 
T

Tom Ogilvy

PrivateSub Commandbutton1_Click()
With listbox1
for i = 0 to .listcount - 1
if .selected(i) then
for each chtObj in Activesheet.ChartObjects
if lcase(chtObj.Chart.Name) = lcase(.list(i)) then
chtObject.Chart.Printout
Exit for
end if
Next
end if
Next
End with
End Sub

Assumes the chart name is the same as the entries in the listbox.
Untested, but this should be close.
 

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