Originally Posted by
Opv
... Specifically, I would like a macro which I can assign to a command button so that whenever I click the button the desired special character (ALT 0149) is inserted....
----- EDIT -----
Just to clarify, my objective would be to insert the desired character even if in edit mode....
I see two issues, which you can easily test and see for yourself.
- As westconn has pointed out, code doesn't run when a cell is in edit mode. At least as far as I know, this is by design (intentional) and (again, AFAIK) not something one can alter.
- While in edit mode, when you go click on your command button, the first thing (or at least awfully close to the first thing) that happens is that as the focus changes to the command button, the cell exits edit mode. So right there, you can see that even if you could get the code started whilst in edit mode, the click on the command button forcing an exit to edit mode would lose where the cursor was inside the string. Does that make sense?
Just to show the part about edit mode prohibiting execution, copy this to a Standard Module:
Option Explicit
Private NextTime As Date
Sub StartIt()
NextTime = Now + TimeValue("00:00:05")
RepeatMe
End Sub
Sub StopIt()
Application.OnTime NextTime, "RepeatMe", , False
End Sub
Sub RepeatMe()
MsgBox "Code ran at " & Format(NextTime, "nn:ss")
NextTime = Now + TimeValue("00:00:05")
Application.OnTime NextTime, "RepeatMe"
End Sub
Now in Sheet1 of a standard new/blank workbook, add an ActiveX commandbutton, and use:
Option Explicit
Private Sub CommandButton1_Click()
Static bolToggle As Boolean
bolToggle = Not bolToggle
If bolToggle Then
StartIt
Else
StopIt
End If
End Sub
Just as an idea (and not thought through at all really), you might want to try using the sheet's (or the workbook's) right-click (or the event of your choice) event in a specific range to run a userform. Said form could have a textbox where manipulating the string would seem easy.
Hope that helps,
Mark