Finding the Current Font.

D

DWTSG

I have some code:

Private Sub Document_New()

Dim result As Integer
Dim stCurFont As String
stCurFont =
MsgBox (curFont)


result = MsgBox("The current font is stCurFont. Do you want to change it?",
vbQuestion + vbYesNo)

If result = 6 Then
Dialogs(wdDialogFormatFont).Show

End If

If result = 7 Then

End If


End Sub

When a new document is created from this template I would like to prompt the
user with the current font and then give them a chance to change it. I am
having trouble just finding what the current font is. I have a string
variable named stCurFont and I would like to set that equal to the current
font and then display it in the message box. Any suggestions?
 
M

martinique

Depends what you mean by the 'current font'. You can get the font of the
current selection using

Selection.Characters(1).Font.Name

[Just check the first character because the selection as a whole will have
no defined font if there is more than one font in the selection.]


For your purposes you might want the font defined for the normal style
(which is also what you need to change if you want to set a new font for the
document):

ActiveDocument.Styles("Normal").Font.Name
 
M

Mark Tangard

See my reply to your earlier thread. (BTW it helps to use the same
subject line, not begin a new one each time you add information.)
As I hinted there, the notion of a "current font" is not really
a Word-compatible concept. But you evidently mean the font of the
first or only character ( = a paragraph mark if the body of the
template contains no text) in the new doc that launches from your
template. In that case, what you want on line 3 is

stCurFont = ActiveDocument.Characters(1).Font.Name

Again, this is somewhat awkward code. In any case, you don't need
the last 2 lines of code shown below.
 

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