Printing text from a textbox in a userform using vba code

Z

Zigball

First of all I have many issues and I am thankful for this website for
discussion purposes and any others - thanks all and thank you google
groups. I am having trouble getting a userform to print what is in a
textbox or I could even settle for it printing from an specific set of
cells in a excel worksheet using the userform and a command button to
intiate the process? I hope I am clear probably I am not I apolligize.
I also could settle for being able to include hyperlinks into a
userform after searching and excel sheet and retrieving data from
specific cell on a worksheet.

This is my example of trying to get the userform to print the value of
textbox2

Private Sub CommandButton2_Click()
UserForm1.texbox2.Text.PrintOut Copies:=1, Collate:=True
End Sub
 
S

Susan

i don't think you can just print the value.
you have to transfer the value onto a worksheet
and then print that.
This is my example of trying to get the userform to print the value of
textbox2

Private Sub CommandButton2_Click()
UserForm1.texbox2.Text.PrintOut Copies:=1, Collate:=True
End Sub

Private Sub CommandButton2_Click()
Range("A1").Value = textbox2.Value
ActiveWorksheet.PrintOut
End Sub

xxxxxxxxxxxxxxxxxxxx
susan
 
T

Tom Ogilvy

for hyperlinks on a userform:

http://www.j-walk.com/ss/excel/tips/tip71.htm
as John Walkenbach's site.

If you want to print the userform including the textboxes:

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

'Public Const VK_SNAPSHOT = &H2C

Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:




Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, _
KEYEVENTF_EXTENDEDKEY, 0 ' key down
keybd_event VK_SNAPSHOT, 0, _
KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, _
KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, _
KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", _
Link:=False, DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub
 
Z

Zigball

Thank You Susan this was a great help!
Susan said:
i don't think you can just print the value.
you have to transfer the value onto a worksheet
and then print that.


Private Sub CommandButton2_Click()
Range("A1").Value = textbox2.Value
ActiveWorksheet.PrintOut
End Sub

xxxxxxxxxxxxxxxxxxxx
susan
 
Z

Zigball

Thank You Tom I will try this, Thanks!

Tom said:
for hyperlinks on a userform:

http://www.j-walk.com/ss/excel/tips/tip71.htm
as John Walkenbach's site.

If you want to print the userform including the textboxes:

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

'Public Const VK_SNAPSHOT = &H2C

Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:




Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, _
KEYEVENTF_EXTENDEDKEY, 0 ' key down
keybd_event VK_SNAPSHOT, 0, _
KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, _
KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, _
KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", _
Link:=False, DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub
 

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