Use VBA to return font and character code selected in Insert Symbol gallery

In PowerPoint, I'm trying to find a way to allow the user to select any symbol from the built-in Insert Symbols gallery, and capture the font and character code (Unicode) selected.  I don't really want to insert the symbol at all, rather simply intercept the results of the dialog and do something else with them.

I know I can present the Insert Symbol gallery by using  Application.CommandBars.ExecuteMso ("SymbolInsert"),  but I don't know how to capture the results.

I've used the following code elsewhere in PowerPoint to present a filepicker and capture the name of the file chosen, but I think filedialogs are a different animal.  But this gets close to what I'm trying to do.

Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Select Background Image"
fd.InitialFileName = backpixfolder

With fd
    If .Show = -1 Then
        pickedpix = .SelectedItems(1)
    Else
        Exit Sub
    End If
End With

Open in new window


Thanks!
Bryce BassettFreelance VBA programmerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JSRWilsonCommented:
I don't think there's any simple way to do that. Maybe if you say WHY you need this there might be an alternative.
0
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
Yep, I agree with JSRWilson. It's not like the FD box in that it can insert symbols while remaining open therefore it's not returning a single value or object per sae. If I was trying to do what you describe, I would develop my own dialog box with 100% control over functionality and then rebuild the Insert tab in XML with all of the standard MS groups and controls, except the Symbol one and then add my own in that position. As John says, not simple.
0
Bryce BassettFreelance VBA programmerAuthor Commented:
Thanks for your input.

What I am trying to do is create a custom symbols gallery on the ribbon as a dropdown.  So the user has access to 20 or 30 commonly used symbols, without having to dig through the much larger insert symbols menu.

I already have a similar button for logos, icons, and country flags, but those are all graphic files, and my ribbon code is simply iterating the folders where those are kept to create the gallery, which can expand over time.  But I want the symbols to be text, not graphics.

dropdown
I've figured out a way to put symbols in a gallery using the following code (assuming there's a ChrW equivalent to every font+code combination, which I haven't yet explored.  

Sub SymbolGallery_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
'This callback runs for every item (label).

    Dim Labelname As Variant
    Labelname = Array("A", "B", ChrW(8657), "D", "E", "F", "G", "H", "I", "J", "K", "L")
    
    On Error Resume Next
    returnedVal = Labelname(index)
    On Error GoTo 0
    
End Sub

Open in new window


Now what I need is a simple way for the user to add a symbol to the gallery.  That's where I thought taking them to the symbol gallery, let them pick any symbol they want, and add it to my gallery.  

I've read that cut and paste is not reliable when you get into Unicode fonts, but I'm not very experienced with those.  There probably is an easier/better way to do this.  I would welcome your ideas!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JSRWilsonCommented:
There's no way (well no easy way without APIs) to select the symbol selected in the ribbon.

It is probably SLIGHTLY easier to add a symbol to the slide , select it and have it add to your own gallery. This is still very tricky coding though. You would need to research RibbonX Dynamic galleries. But if you are not an expert be warned this is as tricky as it gets in ribbon coding.

You might also want to buy the Ken Puls (et al) book
http://www.amazon.co.uk/RibbonX-Customizing-Office-2007-Ribbon/dp/0470191112
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bryce BassettFreelance VBA programmerAuthor Commented:
Thanks for the pointers.

I had thought of using this interim step of adding the symbol, selecting it to identify, then adding it to the gallery.  The code below works identifies the selected symbol in Word, but does not work in PowerPoint.  Is there a way to adapt this code or this concept to work in PowerPoint?

Sub GetCharNoAndFont()

With Dialogs(wdDialogInsertSymbol)
    Debug.Print "Font: " & .Font
    Debug.Print "Char number " & .CharNum
End With

End Sub

Open in new window


http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm

Thanks.
0
Bryce BassettFreelance VBA programmerAuthor Commented:
John, Janie, thanks for your help on this one.   Before I close the question, I had one more request.  I've abandoned the idea of using the symbol gallery to add symbols or building my own.  The user has an Excel worksheet to which they can add Unicode numbers manually (see bottom image below).  That sheet is read in an array called gallerysymbols each time the add-in launches, and the following code creates the symbol gallery.  When the user clicks on the gallery, the appropriate symbol is either added to the selected text box, or shape, or if nothing is selected it is added as its own new texbox.

Sub SymbolGallery_getItemCount(control As IRibbonControl, ByRef returnedVal)

Dim x As Integer

If symbolsloaded = False Then Call loadsymbols

For x = 0 To UBound(gallerysymbols)
labelname(x) = ChrW(gallerysymbols(x))
Next x
    
returnedVal = UBound(gallerysymbols) + 1

End Sub

Sub SymbolGallery_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
'This callback runs for every item (label).

On Error Resume Next
    returnedVal = labelname(index)
On Error GoTo 0

End Sub

Sub SymbolGallery_Click(control As IRibbonControl, id As String, index As Integer)

If Application.Presentations.Count = 0 Then
    MsgBox "A Presentation must be open to use this command."
    Exit Sub
End If

Dim junk As Integer
On Error GoTo tellme
junk = UBound(gallerysymbols)

Call insertsymbol(gallerysymbols(index))
Exit Sub

tellme:
MsgBox "Ribbon needs to be reloaded. Save work, close and re-open PowerPoint.", vbExclamation

End Sub

Sub insertsymbol(ByVal unicode As Long)

Dim myshp As Shape
Dim newbox As Shape
Dim currentslide As Slide
Dim junk As Integer

On Error GoTo tellme
junk = ActiveWindow.Selection.ShapeRange.Count

Select Case ActiveWindow.Selection.Type
    Case ppSelectionText
        ActiveWindow.Selection.TextRange.text = ChrW(unicode)
    Case ppSelectionShapes
        Set myshp = Application.ActiveWindow.Selection.ShapeRange.Item(1)
        myshp.TextFrame.TextRange.text = ChrW(unicode)
    Case Else
        GoTo tellme
End Select
Exit Sub

tellme:
On Error GoTo 0

Set currentslide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)
Set newbox = currentslide.Shapes.AddTextbox(msoTextOrientationHorizontal, 325, 120, 60, 60)

With newbox.TextFrame.TextRange
.Font.Size = 30
.Font.Italic = False
.Font.Bold = False
.text = ChrW(unicode)
End With
newbox.TextFrame2.AutoSize = msoAutoSizeShapeToFitText

MsgBox "The Symbol has been inserted into a new text box in the upper middle of the slide.  If you want to insert it into an existing textbox or shape, first position your cursor inside a textbox where you want to insert the symbol, or select a shape that can contain text."

End Sub

Open in new window


All is working fine for me, but my user complains that a couple of my Unicode numbers display in the gallery (and insert on the slide) as a rectangle instead of the proper symbol.  

Here is what I see:

symbol gallery
Here's what she sees:

symbol boxes
Any idea why these two codes (9855 and 9888) would be showing up as boxes for her?  

Thanks!

Note that the symbols below are just for reference.  Only the numbers are read in by the automation.
symbol sheetsymbolboxes.png
0
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
I couldn't replicate this by using VBA to insert the missing symbols into a textbox but am wondering if it's something to do with the font  your user is setting. Of course the font must contain the glyph for the charcode specified in order for it to be displayed but what I'm unsure about is how PowerPoint is handling that when the glyph is missing, e.g. in the case of a non-unicode font or a unicode font without all glyphs represented. For example, I set the font for my test textbox to courier (where I assume the wheelchair 9855 glyph is missing) but it still appeared.

Mind you, I don't think this could explain the ribbon behaviour, just perhaps the slide result.
0
Bryce BassettFreelance VBA programmerAuthor Commented:
Still haven't found an answer as to why it works for me but not my client, but I have to close this question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.