I have macros for inserting specific characters, but in some cases I need to
use a font that is different from the main body of the text. I want to make
the macro universal, so that no matter what the original font is, the macro
will identify that font, then insert the symbol which may specify a different
font, and then after the insert reset the font back to the original. Stated
otherwise I need to know how to identify the default font type, so I can
return to it.

Re: How to identify current format data for use in macros? by Klaus

Klaus
Wed Aug 01 22:12:17 CDT 2007

"dnatasha" wrote:
>I have macros for inserting specific characters, but in some cases I need
>to
> use a font that is different from the main body of the text. I want to
> make
> the macro universal, so that no matter what the original font is, the
> macro
> will identify that font, then insert the symbol which may specify a
> different
> font, and then after the insert reset the font back to the original.
> Stated
> otherwise I need to know how to identify the default font type, so I can
> return to it.


Hi,

First, I'd try to avoid symbol fonts as much as possible. The fonts most
Word documents use, Arial and Times New Roman, contain over 1600 characters
and symbols.


If you do need to insert symbols, the font of the preceeding and following
text isn't changed.

You could use something like

Selection.Collapse(wdCollapseEnd)
Selection.InsertSymbol _
Font:="Symbol", _
CharacterNumber:=97, _
Unicode:=True

(in this case an alpha, code 97, from the Symbol font).

Another good option would be a symbol field.

Selection.Collapse(wdCollapseEnd)
ActiveDocument.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldSymbol, _
Text:="97 \f ""Symbol""", _
PreserveFormatting:=False


Both the methods above are good because they make sure you don't
accidentally change the font later on -- say by (re)applying a style, or
resetting the formatting with Ctrl+Spacebar = ResetFont.
If you'd just insert the character with .TypeText or .InsertAfter and apply
the symbol font, that wouldn't be the case.

Regards,
Klaus



Re: How to identify current format data for use in macros? by Klaus

Klaus
Wed Aug 01 22:29:31 CDT 2007

... I forgot to answer your original question.

You could remeber the current font (name, size, color, the whole shebang)
like this:
Dim myFont As Font
Dim myRange As Range
Set myFont = Selection.Font.Duplicate


and later apply it:
myRange.Font = myFont

But if you're working with styles, you may just as well forget about that
and just use
Selection.Font.Reset
which will return the font to whatever is defined in the style.

Regards,
Klaus



Re: How to identify current format data for use in macros? by dnatasha

dnatasha
Fri Aug 03 00:54:01 CDT 2007

I still have not been able to get this to work. Perhaps I should give an
example of what I am trying to do. I am writing along using the font
Verdana and I want to insert an up arrow symbol. There is no up arrow in the
character set for Verdana, so I use a macro in which I insert this symbol
using Arial Black. I include in the macro a provision to return to Verdana
after the insert, so I can continue to enter text in Verdana. This all
works fine. However, I want the to be able to use this macro no matter what
the general text font is, so I don't have to revise the macro each time I use
a different font.

I generally set up macros using the record macro function, and then edit
them to tweak them. I have limited experience programming visual basic from
scratch, especially for Word. I get run time errors trying to use the code
for capturing and resetting the current font.



Re: How to identify current format data for use in macros? by dnatasha

dnatasha
Fri Aug 03 01:58:00 CDT 2007

On further trial and error I have found that your comment that inserting the
symbol does not change the font of the preceding and following fonts to be
accurate. I do not have to specify the font I want to return to, as it will
automatically do this. There was an additional step I included that was
causing the following font to retain that of the symbol. This happened when
immediately after inserting the symbol I highlighted it to change it to bold.
Using Ctrl-spacebar will reset the font to that of the current style, not
the prior text. I could, of course, avoid this by typing another character
before going back to highlight the symbol. I still would like to be able to
capture and return to the previous font. I don't know if your method would
do this (or would it return to the previous style?) since when I include the
last line [myRange.Font = myFont] I get the run-time error.

Re: How to identify current format data for use in macros? by Russ

Russ
Sat Aug 04 05:36:30 CDT 2007

See below,
> On further trial and error I have found that your comment that inserting the
> symbol does not change the font of the preceding and following fonts to be
> accurate. I do not have to specify the font I want to return to, as it will
> automatically do this. There was an additional step I included that was
> causing the following font to retain that of the symbol. This happened when
> immediately after inserting the symbol I highlighted it to change it to bold.
> Using Ctrl-spacebar will reset the font to that of the current style, not
> the prior text. I could, of course, avoid this by typing another character
> before going back to highlight the symbol. I still would like to be able to
> capture and return to the previous font. I don't know if your method would
> do this (or would it return to the previous style?) since when I include the
> last line [myRange.Font = myFont] I get the run-time error.

You haven't set myRange to anything yet, hence the error. After moving to
the right of the symbol, you could use:
Set myRange = Selection.Range
myRange.Font = myFont

>> You could remember the current font (name, size, color, the whole shebang)
>> like this:
>> Dim myFont As Font
>> Dim myRange As Range
>> Set myFont = Selection.Font.Duplicate
>>
>>
>> and later apply it:
>> myRange.Font = myFont
>>
>> But if you're working with styles, you may just as well forget about that
>> and just use
>> Selection.Font.Reset
>> which will return the font to whatever is defined in the style.
>>
>> Regards,
>> Klaus



--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID