Print VBA Srting

Posted on 2016-08-19
Medium Priority
Last Modified: 2016-08-19
Is it possible to print a string with vba? For example:
    Dim test As String

Open in new window

Question by:wiredemc12
  • 2
  • 2
LVL 37

Expert Comment

ID: 41762528
Print it where?

Author Comment

ID: 41762534
I want to print text to the printer, but I do not want to store the text in any of the worksheets
LVL 31

Expert Comment

by:Helen Feddema
ID: 41762580
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)
   Set rng = sht.Range("A3")
   rng.Value = strText
   rng.Value = ""
End Sub

Open in new window


Author Comment

ID: 41762834
I dont want to put the text into the worksheet. Is this impossible?
LVL 31

Accepted Solution

Helen Feddema earned 2000 total points
ID: 41763061
I don't think so, but at least this method doesn't leave anything in the worksheet.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question