• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

VBA (word): How to print selected text

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
wonda04
Asked:
wonda04
1 Solution
 
TimCotteeCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now