Macros to display Symbol Font items.

R

Robert

I am trying to write text slides in a foreign language which needs me
to borrow items from the Symbol font. As a VBA newbie I have carefully
recorded each of the macros. They take this form:

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange _
..Characters (Start:=1, Length:=0).Select
ActiveWindow.Selection.TextRange.InsertSymbol _ FontName:="Arial",
CharNumber:=601, Unicode:=msoTrue
End Sub

The problem is that when run the macros leave the displayed character
selected. When the next character is inserted from the keyboard, the
VBA character is deleted. What should I add to the macro please.

All suggestions gratefully received. TIA

Robert.
 
B

Brian Reilly, MVP

Robert,
If you have the text frame selected, it will not change teh selection
with the following.

Sub test()
With ActiveWindow.Selection.ShapeRange.TextFrame.TextRange _
..Characters(Start:=1, Length:=0)
ActiveWindow.Selection.TextRange.InsertSymbol _
FontName:="Arial", CharNumber:=601, Unicode:=msoTrue
End With

End Sub

If you have the text selected you can just add
ActiveWindow.Selection.Unselect at the end.

Brian Reilly, MVP
 
R

Robert

Sorry Brian, but this produces the same effect as before. The symbol is
left selected after the macro runs and when anything further is typed
the Symbol just disappears.

Moreover, adding "Unselect" in the way you suggest deselects the
placeholder and nothing further can be added to it.

Any further suggestions, please?

Robert.
 
B

Brian Reilly, MVP

Robert,
I beg to differ (g).
Try this. Click in the placeholderor textbox and press the Esc key to
select the textframe. Now run the macro and continue typing.
Works here.

Brian Reilly, MVP
 
R

Robert

Sorry Brian. I wonder if we have the same versions. My PPT is 2002
with VBE 6.3 .
I have tried what you suggest including (for the first time ever)
pressing ESC to select the textframe. I have also run the code both
with and without the final "Unselect" line that you suggested. The
results are as follows:

Without the Unselect line, the macro runs and displays the Symbol but
leaves it selected. If typing continues the first character overwrites
the Symbol. I CAN put all to rights by pressing Rt Arrow each time the
Symbol is used, but (please!) I have several hundred slides to write.

With the Unselect line in the coding, the macro runs and displays the
Symbol but it removes the cursor and the two placeholders and refuses
to accept any further keyboard input by locking completely.

As you would expect I pasted the code directly from the newsgroup post.

I don't quite understand your reference to the Text Frame, obtained by
pressing ESC. It has been enough until now to click in the placeholder
to be able to display text or Symbols, albeit manually with all the
mousework that that entails.

Thank you so far. Research continues!

Robert.
 
R

Robert

Thanks Brian. We may perhaps have different versions - mine is PPT
2002 with VBE 6.3 .
I'm afraid things are just the same. I have tried your test sub with
and without the final line, but neither works properly.

Without the "Unselect" line, the macro runs, produces its Symbol at the
cursor but leaves it selected. If I continue typing the first
character overwrites the symbol just displayed. There is no space
between them. I CAN remove the highlight by pressing Rt Arrow. Then
everything continues as normal. (But I have several hundred slides to
write!)

With the "Unselect" line, the macro runs and displays the Symbol, but
it also removes the cursor, removes the Title and Text placeholders and
refuses to accept any further keyboard input.

Naturally, so as not to make any errors in coding, I pasted your test
Sub from the forum.

One thing puzzles me though. I have never before needed to press
Escape before typing. One click in the Placeholder was enough to
display whatever I needed (albeit manually). I can't quite understand
why that should be necessary now.

Thank you for your efforts so far. Research continues!

Robert.
 
B

Brian Reilly, MVP

Robert,
I'm in PPT 2003. Don't have any machines around here to test on PPT
2002.

Only other thought at moment is to set a variable to the number of
characters in the current textbox string and then reposition the
cursor to that variable +1 or +2 depending on how you handled te
variable setting. But that's just a guess at moment and not even
tempted on PPT 2003 since I'm not truly sure what/how you are trying
to do this. Maybe you could explain a little more and post some more
code, if appropriate.

Brian Reilly, MVP
 
J

JanAdam

If right arrow works in manual mode I would try to add the following line to
your code
SendKeys ChrW({Right})
after you inserted your symbol. Or, I would use SendKeys ChrW (decimal code
for your character) to insert the symbol you needed.
 
R

Robert

Thank you Jan for your reply. Your thinking is like mine - if it works
from the keyboard then it could be made to work from VBA. I've tried
to implement the first of your suggestions but am having difficulty in
getting it to compile. I am uncertain what should precede the SendKeys
command. At present the line reads:
ActiveWindow.Selection.TextRange.SendKeys ChrW({Right})
but this throws up a couple of errors, namely, SendKeys isn't related
to TextRange (or to anything else I can find), and the curly braces are
seen as invalid characters.

I did think of inserting the Unicode value of "Right Arrow", but
couldn't find it.

Remembering that I am a VBA newbie, may I ask you to be very specific
about your earlier suggestion. Thanks in advance.

Robert.
 
R

Robert

Would anyone else care to contribute to this debate? I feel we are no
nearer to finding a solution to this (deceptively?) simple problem.

I have to write nearly two hundred text-only slides whose slightly
resized Title and Text Placeholders will be filled with a foreign
language with Latin letters and about 9 others which are available from
the Symbol Font. I only need therefore to insert the symbols as needed
while writing on the slides.

I recorded a few trial Macros whose coding is in my first post. They
displayed the Symbols, but left them highlighted (=selected). When
writing at the keyboard I can remove the highlighting in one of three
ways: by clicking in the text line; by hitting the End key; or by
hitting Right Arrow. If I don't do one of those actions, writing the
next character in the word clears the highlighting but also deletes the
Symbol just created.

All that needs to be done is to find a programmatic equivalent of one
of those methods.

Given the amount of work to be written, and that these symbols can
occur 4 or 5 times in a single word, I really need to remove the
highlighting within the macro.

Can anybody else help, please? Thank you.
Robert.
 
S

Shyam Pillai

'-----------------------------------------------------------------
Sub Sample()
Dim oTextRng As TextRange
ActiveWindow.Selection.ShapeRange.TextFrame _
.TextRange.Characters Start:=1, Length:=0

' InsertSymbol method will return a reference to the character (textrange)
just inserted.
' we'll make use of it to make the cursor move to the next character.

Set oTextRng = ActiveWindow.Selection.TextRange _
.InsertSymbol(FontName:="Arial", CharNumber:=601,
Unicode:=msoTrue)

' Place the cursor at the location just after the inserted character
' and make it select 0 characters.

ActiveWindow.Selection.ShapeRange.TextFrame _
.TextRange.Characters(oTextRng.Start + 1, 0).Select

End Sub
'-----------------------------------------------------------------
 
R

Robert

Hi Shyam. Thank very much for your reply.
I am delighted to say that your coding works perfectly and has put an
end to too many days of fruitless experiments.
I have now assigned the nine macros to Keyboard Shortcuts via Chirag
Dalal's Shortcut Manager and I can now type my texts furiously.
Thank you for restoring my serenity.
Robert.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top