Tuesday, November 25, 2008

How to insert Symbols in Word Document using VBA

Here is a simple way to insert the commonly used symbols (Copyright, Trademark etc) using Word VBA

Sub Insert_Symbols_Example()

Selection.TypeText Text:="Copyright "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=169, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Trade mark "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=8482, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Registered Symbol "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=174, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:=" EURO"

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=8364, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Pound "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=163, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Yen "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=165, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Degrees "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=176, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Plus Minus "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=177, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Multiplication Sign "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=215, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Division Symbol "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=247, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Square Root "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=8730, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Ohm Sign "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=8486, _

Unicode:=True

Selection.TypeParagraph

Selection.TypeText Text:="Dagger "

Selection.InsertSymbol Font:="Times New Roman", CharacterNumber:=8224, _

Unicode:=True

End Sub



VBA Insert CopyRight Symbol, VBA Insert Trade mark, VBA Insert Registered Symbol, VBA Insert EURO Sign, VBA Insert Pound Sign, VBA Insert Division Symbol, VBA Insert Square Root Symbol,

See also:

Add Words to AutoCorrect Entries


6 comments:

  1. hi thier,
    thanks for your hints on inserting symbols using VB for word documents.

    i have been searching the net on how do i read symbols in vb from a word document taking into consideration that each symbol comes from a diffrent font table/ charecter table.

    i have developed a simple code to do so but each time the program reads the file and when it reaches the symbol its give a incorrect charecter and incorrect unicode number. i have tested to program to read normal english charecters it works fine and gives the correct unicode number using the ASC() function.

    my question is how do i read symbols in word document using VBA, is thier any method/function/property that does this .?


    thanks

    ReplyDelete
  2. Anonymous6:29 PM

    Search Symbols in Word Document

    Can you check if http://vbadud.blogspot.com/2008/12/convert-symbols-to-entities-using-word.html is close to your needs

    Thanks

    ReplyDelete
  3. thanks for you support the link that you have mentioned is helpful however frim the code that i saw is a bit diffrent than what i did but it would be the same.

    i will refraze my question :) and i hope you would be able to help.

    a have a word document that has several letters/symblos

    for example the document includes several letters with few symbols
    if i wanted to check if the first charecter it reads is it a letter or symbols?

    the answer would be
    check font name then check subset name then get the unicode hed number. or is this any other solution to know which is which ?

    for example number 6 has
    - unicode (hex): 0036
    - fontname: normal text
    - subset: basic latin

    while a barcode "Digit Six" symbol that represents the value 6 has
    - unicode (hex): 0036
    - fontname: 3 of 9 barcode
    - subset: <=== no subset



    thanks in advance

    ReplyDelete
  4. Anonymous1:08 PM

    You can try the following:
    1. select the text to be read
    2. xml_dat = Selection.FormattedText.XML

    in the xml data it is visible that a symbol font is used:
    e.g.
    Unfortunately the xml data also includes a lot of overhead, but I don't know a better solution.

    ReplyDelete
  5. Ishana11:06 PM

    I have also found a link where you can find code for adding different word elements into your documents. For me it was very helpful, i hope it will help others also.

    http://www.aspose.com/docs/display/wordsnet/Inserting+Document+Elements

    ReplyDelete
  6. http://word.mvps.org/faqs/macrosvba/FindReplaceSymbols.htm

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.