Printing text from a textbox in a userform using vba code

  • Thread starter Thread starter Zigball
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Hi Susan,
I did try your code but its not working.


i don't think you can just print the value.
you have to transfer the value onto a worksheet
and then print that.

Zigball wrote:
> 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
 
Back
Top