View Single Post
 
Old 03-28-2013, 05:32 PM
AlexR AlexR is offline Windows XP Office 2007
Novice
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Default

Ah, thank you!! I combined your answer with some code I found elsewhere for a perfect result!

I'm using this to automatically close the Userform:

Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
 
Private Sub UserForm_Activate() 
    DoEvents 
    Sleep 500 
    Unload Me 
End Sub
(Source: http://www.ozgrid.com/forum/showthread.php?p=506767)


I also came up with this, to close the form with any keystroke and return the character, but I'm still getting some wonky results with non-alphanumeric keys. Your way works better, but just in case this might be useful to someone else:
Code:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If Shift = 0 Then Selection.TypeText LCase(Chr(KeyCode))
    If Shift = 1 Then Selection.TypeText Chr(KeyCode)
    Unload Me
End Sub
Reply With Quote