View Full Version : [SOLVED:] Special Characters
Is there a way to simulate a series of key strokes which generate a special character within a cell? 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. I explored SENDKEYS but, unless I am overlooking something, that does not appear to be what I need. Also, I can't record such a macro. Is such a macro possible?
----- EDIT -----
Just to clarify, my objective would be to insert the desired character even if in edit mode. For example, if I already have a word in a cell and I want to divide the syllables with the said character, I would want to be able to position the cursor at the appropriate place, click the button and insert the said character at the position of the cursor, without replacing the existing cell content.
ashleyuk1984
12-29-2013, 12:49 PM
You can copy and paste that character • into the project.
Maybe place this into a variable ?? Maybe you could supply us with an example workbook with your code and we'll see what we can do.
Maybe we can come up with a better more reliable way than "sendkeys".
At this point I'm only testing an idea in a blank workbook.
westconn1
12-29-2013, 01:08 PM
you can do this simply from the keyboard, as long as your know the code for the character
AFAIK no code will work while in edit mode
you can do this simply from the keyboard, as long as your know the code for the character
AFAIK no code will work while in edit mode
Thanks. Yes, I'm aware of the keyboard option. I was just trying to see if there was a way to automate the process.
... 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
Thanks, Mark. After reading and testing your reply, I don't think my original idea is worth pursuing further. The keyboard option appears to be the most simple viable option. I appreciate the help.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.