Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jan 2004
    Location
    Johannesbutg, South Africa
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    In earlier versions of Word, I am able to run VB code from an external VB app to open the Word InsertSymbol dialog box, and after the user has selected the symbol and inserted it into the document, close Word and get the symbol's font, character number, etc. With Word XP, the font is returned, but CharNum is always 0. A std macro captures the CharNum correctly, but I have to get at it via the VB app.

    DLS

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    There was a lament about this almost two years ago (<post#=125510>post 125510</post#>) and I'm not sure anyone has posted a solution.

    What is the difference between your macro code and your VB code? Maybe we can help make them work the same way.

    Would it be out of the question to interrogate the inserted character using, for example, Selection.Previous.Text? or AscW(Selection.Previous.Text)?

    If you search for posts on Symbol fonts by Klaus Linke you will find a wealth of information, some of which could help with the above approaches.

  3. #3
    New Lounger
    Join Date
    Jan 2004
    Location
    Johannesbutg, South Africa
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    I phrased my comment about the VBA macro incorrectly. When recording a macro, the character is captured and included in the macro code, but even a VBA macro that displays the InsertSymbol dialog box and tries to get at the CharNum of the character entered does not have any success. Will try your other suggestions.

    Many thanks
    DLS <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

  4. #4
    New Lounger
    Join Date
    Jan 2004
    Location
    Johannesbutg, South Africa
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    Hi

    I tried to interrogate the inserted character, but no luck. The ascii/ascW value returned is related to the font displayed (e.g. Arial/Times New Roman) rather than the actual font, e.g. Symbols/Wingdings, etc. It refuses to return the value from the extended unicode set, except for some of the standard symbols, e.g.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    Out of ideas? Did you search for posts on symbol fonts by Klaus Linke?

    Try this:

    <pre>Dim strFont As String, lngCharNum As Long
    Selection.Previous.Select
    With Dialogs(wdDialogInsertSymbol)
    strFont = .Font
    lngCharNum = .CharNum
    End With
    Selection.Collapse wdCollapseEnd
    MsgBox "Font = " & strFont & vbCrLf & "Symbol = " & lngCharNum</pre>

    I'm not sure whether you like getting a negative number, but I can't recall how to convert it. Again, Klaus probably has posted this in the past. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    <pre>lngCharNum = .CharNum And &HFFFF&</pre>


    Integers (2 Bytes) are signed in VBA.
    Integers greater than &H7FFF (32767) come out negative.
    Unicode needs 2 bytes, too, but you'd usually like to have the code positive.
    (ChrW won't complain if you feed it a "negative" Integer)

    The expression above forces a conversion to a "Long" integer (4 bytes) through the "&" at the end of "&HFFFF&".
    It then "masks" the upper 2 bytes of .CharNum ... it sets them to zero with "And &H0000FFFF".

    You'd get the same result if you add 2^16 in case the number comes out negative.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  7. #7
    New Lounger
    Join Date
    Jan 2004
    Location
    Johannesbutg, South Africa
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    <P ID="edit" class=small>(Edited by jscher2000 on 28-Jan-04 13:57. Surrounded code with [pre] and [/pre] tags to preserve indenting.)</P>Thanks for steering me in the right direction.

    This is the code that I managed to get from the VB app (has to be slightly more specific with reference to the word objects than straight VBA)
    <pre> Set lDlg = mWApp.Dialogs(wdDialogInsertSymbol)
    lDlg.Display
    'if Word version is XP or greater, use this code
    If mWordVersion > 9 Then
    mWApp.Selection.Previous.Select
    With mWApp.Dialogs(wdDialogInsertSymbol)
    lFont = .Font
    lCharNum = .charnum
    End With
    mWApp.Selection.Collapse wdCollapseEnd
    ' MsgBox "Font = " & lFont & vbCrLf & "Symbol = " & lCharNum
    If lFont <> "(normal text)" Then
    lCharNum = lCharNum + 4096
    End If
    Else
    lFont = lDlg.Font
    lCharNum = lDlg.charnum
    End If</pre>

    If the slected symbol is not actually a symbol, but part of another font set, the user still has to manually capture the font name, as except for the Wingdings & Webdings fonts, (normal text) gets returned. But its much better than I had it before.
    Much obliged for your assisance
    DLS
    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word XP InsertSymbol dialog doesn't retain CharNum (Word XP)

    I'm glad it works. You might be capturing this elsewhere in your code, but for anyone wondering how to determine mWordVersion, you can access the version number using:

    mWApp.Version

    This returns the version in a string with one decimal place (e.g., Word 2000 = 9.0, Word 2002 (XP) = 10.0).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •