We help IT Professionals succeed at work.

VBA Display the unicode values of the selected cell

I am working on an Arabic language Excel document.  I need a macro or other method of displaying the unicode values in a cell when I execute it.  I am 1 day into VBA but have figured out how to open the Excel developer tab and access the VB window.
Comment
Watch Question

Expert of the Quarter 2010
Expert of the Year 2010

Commented:
Dim s as String
s = Cells(1,1).Value   'the cell you want to inspect
For i = 1 to Len(s)
  MsgBox AscW(Mid(s,i,1))
Next
Most Valuable Expert 2011
Awarded 2010
Commented:
Hi DonFreeman,

the attached file has a form, code behind that form and a macro called CSB. Select a cell with contant and then run the macro. A form will then show the binary values of the characters in the cell.

You could assign the shortcut key Ctrl-Shift-B to the macro, so you have a memory bridge to CSB (conveniently show binary).

Credit for this code goes to shg over at Excelforum.com.

cheers, teylyn
showbinary.xls

Author

Commented:
I mean it when I said I started VBA yesterday.  Cyberkiwi, I don't know exactly what to do with that. I put it in a submodule?  Create a macro and copy it in?  How do I use it?  I have VBE and  my workbook open.  Now what?

teylyn, I open the document, open VBE, and see a form and a macro.  How/where do I save these and how do I activate them?  I'm sorry that I need some very basic instruction.  Two weeks from now I hope to be much smarter but I'm very ignorant today.

Author

Commented:
OK, Teylyn, I copied some arabic text into a cell in your showbinary.xls and ran the macro.  It worked very well. How do I get that Macro and form out of there and into my personal.xlsb?  export?
Most Valuable Expert 2011
Awarded 2010

Commented:
Don,

start Excel and open the Showbinary attachment from above.
Then open your document. For the sake of this excercise, let's assume it's called MyDoc.xls
Now you have both files open in Excel.
Hold down the Alt key and hit F11 to open the VB Editor
In the left hand pane, you will see ShowBinary and MyDoc as two separate projects
ShowBinary has several modules underneath the sheet modules.
Click the + sign next to Forms in the ShowBinary project
Drag and drop frmShowBinary from ShowBinary onto MyDoc
Click the + sign next to Modules in the ShowBinary project
Drag and drop Module1 from ShowBinary onto MyDoc
Now you should have both a Forms and a Modules folder in the MyDoc project, containing the frmShowBinary form and the Module1 respectively.
Close the VBE and save MyDoc

You should now see the macro CSB in your macro list (Tools - Macro - Macros)
Select a cell, then go Tools - Macro - Macros and run CSB.

Read up about assigning a keyboard shortcut to macros in the help (or google for it). Then assign Ctrl-Shift-B to the macro and Conveniently Show Binary (CSB) for any selected cell.

cheers, teylyn

Author

Commented:
Good start.  I see some possibilities from here.  I will post an additional question building on this one.