Print contents of text box

I have a form with a text box (txtSolution) that lists the step-by-step instructions to complete a task.
On this form I have a command box that allows the user to print out the contents of the list box. What sub procedure code do I need to print out the contents of the text box (no print preview is necessary)?

Sub PrintSolution()

End Sub
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven HarrisPresidentCommented:
I look forward to some Experts chiming in on this one, I have never had the need to print from VBA in this way (yet)!

As an alternative, you could create a new sheet and expand a cell (A1) to page size.  Put the text for your Text box in this cell, then change your ControlSource property to that cell.  Name the sheet, hide it and then add the following to the button:


Open in new window

Hopefully we can get byundt and/or MartinLiss in here, I am sure they will have a solution!
Frank FreeseAuthor Commented:
I haven't seen anything, yet, in my search. Let's see who else chimes in also
Martin LissOlder than dirtCommented:
Printer.Print txtSolution.text
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Frank FreeseAuthor Commented:
I'll try this today and with l the confidence in you I'll bet it'll work.
You make some of this so easy. I searched for a Internet solution and this did not show up.
Frank FreeseAuthor Commented:
I used your code and got run-time error.  See below:
Code used in Sub
NorieAnalyst Assistant Commented:

Printer.Print is for VB, not VBA.

If you want to print the contents of a textbox on a userform you could transfer the contents to a blank sheet, set up the page and then print.

Here's an example of that.
Private Sub CommandButton1_Click()
Dim strContents As Variant
Dim wsTemp As Worksheet

    strContents = Split(Me.TextBox1, Chr(10))
    Set wsTemp = Worksheets.Add
    wsTemp.Range("A1").Resize(UBound(strContents)).Value = Application.Transpose(strContents)
    ' code to set sheet up for printing
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True
End Sub

Open in new window

If you want to print the userform you can use Me.PrintForm.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
imnorie is right. I forgot where I was.
Frank FreeseAuthor Commented:
let me try the me.printform
Frank FreeseAuthor Commented: what I needed from imnorie
thanks everyone
Frank FreeseAuthor Commented:
thanks to all
Much appreciated
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.