Print VBA Srting

wiredemc12
wiredemc12 used Ask the Experts™
on
Is it possible to print a string with vba? For example:
    Dim test As String
    test.PrintOut

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
Print it where?

Author

Commented:
I want to print text to the printer, but I do not want to store the text in any of the worksheets
Top Expert 2009

Commented:
You could write the text string to a cell, print it out using the Range.Printout method, then delete it:
Public Sub PrintText()

   Dim strText As String
   Dim rng As Excel.Range
   Dim sht As Excel.Worksheet
   
   strText = "Test string"
   Set sht = Application.Sheets(1)
   sht.Activate
   Set rng = sht.Range("A3")
   rng.Activate
   rng.Value = strText
   rng.PrintOut
   rng.Value = ""
   
End Sub

Open in new window

Author

Commented:
I dont want to put the text into the worksheet. Is this impossible?
Top Expert 2009
Commented:
I don't think so, but at least this method doesn't leave anything in the worksheet.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial