Solved

VBA (word):  How to print selected text

Posted on 2003-11-18
1
277 Views
Last Modified: 2010-08-05
I have text in a TextBox1 that I'd like to be able to print. I have only been able to print this if my document is blank.  That is, I would use ActiveDocument.PrintOut.  However, if my document has text already, it seems to delete my original text.  I'm stuck as to how to get ONLY the TextBox1 text printed.

I'm attempting to send the textbox text to the document as a selection, have Word print only the selection, then clear the selection.

Anybody know how to print ONLY the selection?

Here is my vba code so far...

           Dim MyRange As Object

           Application.ScreenUpdating = False
           Set MyRange = ActiveDocument.Range
           Selection.InsertAfter (TextBox1.Text)
           MyRange.Collapse
          ' Please help:  HOW to Print this selection?
           Selection.Delete
           Application.ScreenUpdating = True
           Application.ScreenRefresh


Thank you in advance.
0
Comment
Question by:wonda04
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 9772203
Hi wonda04,

Application.PrintOut Range:=wdPrintSelection

Should do it.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 63
Access 2016 VB code 9 102
JSON Response and request in VB6 application 11 239
Best way to parse out a json string in VB6? 10 111
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now