How to print the contents of a textbox that is on a Userform

D

DMS

This problem has been driving me up a wall. It seems very easy but I can't
find the answer anywhere.

I have a Userform with a text box on it. I use this textbox to list errors
that my macro finds. I would like my users to be able to print the contents
of the textbox. Any ideas.

I have tried the following.
Printer.Print Userform1.textbox1.text

When I run this code I get an error that says "Object Required"

Any help would be appreciated.

DMS
 
J

JackD

I'm not sure which language you are using or what printer is set as printer,
but wouldn't it be better to write them to a log file so the user can view
and search them without having to print them? They also have a print option
from just about any application which can open a text file.
I'd do that first. If you want someone to debug your code, you need to give
more information about what programming language you are using. Maybe even
post in an appropriate group. This one is for Microsoft Project which is a
scheduling software.
 
D

DMS

JackD,
I am writing this in MS Project VBA. The tool is a series of forms that the
user uses to export EVMS data and Baselines in a file format that can be
imported by our cost system. Before it creates the .csv it runs a series of
error checks on the data. If it finds any errors it prints it to a textbox
on the userform. In previous versions, the error messages were sent out to a
..txt file, just like you suggested. My users did not like having to go and
open that other file, lazy I guess. So as a result I came up with this new
approach.

So ultimately I would like my users to click a button and have the contents
of the textbox sent to their default Printer. The code that I posted
yesterday was something that I found multiple times on the web. I think it
is just straight VB. "Printer.Print Userform1.TextBox1.Text".

I can't believe that this is impossible to do.

Thanks for the response.
DMS
 
J

JackD

OK, Let's work on the real problem which is user laziness.
Write to a log file (here called mylog.txt and is stored at the root
directory of c:)
Then have your code open the file using notepad.

Here is sample code for doing this.

Sub openLogInNotePad()
Dim retval As Variant
retval = Shell("notepad.exe " & "c:\mylog.txt", vbNormalFocus)
End Sub

I still think this method is more appropriate.
 

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