functions.bas is a VBA module that creates a Forms-text box:
option explicit
sub main() ' {
with activeSheet ' {
dim rng as range
set rng = .range(.cells(2,2), .cells(12, 7))
dim obj as oleObject
set obj = activeSheet.OLEObjects.add( _
classType := "Forms.TextBox.1" , _
link := false , _
displayAsIcon := false , _
left := rng.left , _
top := rng.top , _
width := rng.width , _
height := rng.height _
)
end with ' }
dim tb as msForms.textBox
set tb = obj.object
with tb ' {
.name = "txt"
.font = "Courier"
.enterKeyBehavior = true
.multiLine = true
.borderStyle = fmBorderStyleSingle
.backColor = rgb(255, 240, 100)
end with ' }
end sub ' }
sheet1.bas is the sheet-module that is needed to capture events of form controls placed on a given sheet.
In order to stop a key from being prcocessed, 0 must be assigned to keyCode that is passed to the _keyDown event.
option explicit
private sub txt_keyDown(byVal keyCode as msForms.returnInteger, byVal state as integer) ' {
dim shift, alt, ctrl as string
if state and 1 then shift = "shf"
if state and 2 then ctrl = "ctl"
if state and 4 then alt = "alt"
debug.print _
shift & chr(9) & _
ctrl & chr(9) & _
alt & chr(9) & _
keyCode & chr(9)
end sub ' }