HI!
I want to print data from my ListBox, but i recieve an error on Printer.Print:
Method not found???
May i need to reference a library or something like that?
Thanks in advance,
Ruslan.
Printable View
HI!
I want to print data from my ListBox, but i recieve an error on Printer.Print:
Method not found???
May i need to reference a library or something like that?
Thanks in advance,
Ruslan.
Just a quick question...
Are you using vb6 or vba?
Printer.Print will work only in vb6 and not vba. In vba it will give you that error...
Thanks for the reply!
I use VBA and i can see now why i fail to print.
Is there a way i can print data from ListBox in VBA?
Or i have to wriete my own method/function?
Regards,
Ruslan.
as vba has no methods to print, the normal solution is to fill in a range in a document or worksheet or whatever is appropriate to the application then use the printout method of the range or worksheet or document
pagesetup properties can be used to format the printing
a new sheet or document can be created for the purpose of printing then removed afterwards
there is also the printform method of userforms
You need to 'Transfer' the contents of the ListBox onto a sheet as .printout is only supported by objects like chart, range, worksheet, workbook for example
Code:Dim i As Long
Private Sub UserForm_Initialize()
'~~> Populate Sample Data
For i = 1 To 10
ListBox1.AddItem i
Next i
End Sub
Private Sub CommandButton1_Click()
Dim rng As Range
'~~> Populate From Range("A1") in Sheet1 from listbox
'~~> Please amend as applicable
For i = 0 To ListBox1.ListCount - 1
Sheets("Sheet1").Range("A" & i + 1).Value = ListBox1.List(i)
Next i
'~~> Set the range to print
Set rng = Sheets("Sheet1").Range(Range("A1"), Range("A1").End(xlDown).Address)
rng.PrintOut
End Sub
Edit:
Pete!!!! You beat me to it... :lol:
Thanks Pete!
Actually, at the moment, my printing from ListBox goes through a worksheet, because i didn't find a solution yet.
It is a pleasure for me to hear suggestions that i have already done from such specialists, because i am new to programming and as i discovered, the LOGIC of programming is quite complicated (for me) at the monent. I think this is caused by the lack of experience.
But i hope that everyday working will give more experience in programming.
This week i will install a Visual Studio 2005 on my PC, then ,i think, i will get more power of programming.
Best Regards,
Ruslan.