PDA

View Full Version : Can't use a symbol in macro



wardw
04-10-2017, 10:44 AM
I have a macro that detects a number followed by an SI symbol (mm, Km, etc.), and inserts a nonbreaking space between the number and the symbol. It works fine, but I'd like to include the SI symbol for ohms, which is a Greek omega, and for "micro," which is Word's "micro sign" character. A copy/paste from Word into the macro code just inserts a question mark. How can I specify a symbol in VBA code?

Paul_Hossler
04-10-2017, 11:38 AM
Assuming the font supports the symbols




Sub Macro1()
Selection.TypeText Text:="Omega is " & ChrW(937)
Selection.TypeParagraph
Selection.TypeText Text:="Micro is " & ChrW(956)
Selection.TypeParagraph
End Sub


or using hex



Sub Macro2()
Selection.TypeText Text:="Omega is " & ChrW(&H3A9)
Selection.TypeParagraph
Selection.TypeText Text:="Micro is " & ChrW(&H3BC)
Selection.TypeParagraph
End Sub


If you put your cursor right after the symbol in the document and Alt-x it will show you the hex. Alt-x again will return the symbol

You can type the hex (if you know it) for a special character into the doc and Alt-x will replace the (for e.g.) 03A9 with Omega