Results 1 to 6 of 6

Thread: Please help with printing from ListBox...!

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    41

    Exclamation Please help with printing from ListBox...!

    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.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Please help with printing from ListBox...!

    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...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    41

    Re: Please help with printing from ListBox...!

    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Please help with printing from ListBox...!

    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
    Last edited by westconn1; Dec 14th, 2009 at 05:00 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Please help with printing from ListBox...!

    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)
        
        '~~> Print
        rng.PrintOut
    End Sub

    Edit:

    Pete!!!! You beat me to it...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    41

    Re: Please help with printing from ListBox...!

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width