Prompt for Font Choice

D

DWTSG

I have a template that is pretty basic. I would like the user to be
prompted to make a font choice when a new doc is created from the template.
I am using Win2k. Thanks for the help.
 
D

DWTSG

thanks bunches, here is where I am with my code

Private Sub Document_New()

Dim result As Integer
Dim curFont As String
Dim newFont As String
curFont = ActiveDocument.Characters(1).Font.Name


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

If result = 6 Then
newFont = Dialogs(wdDialogFormatFont).Show


ActiveDocument.Select

ActiveDocument.Styles("Normal").Font.Name = newFont

End If

End Sub

if the user selects yes, the font dialog box will pop up and allow them to
choose a font. one they have chosen I would like to be able to apply that
to the 2 paragraphs that already exist in the document. any ideas?
 
D

DWTSG

Thanks a bunch guys. It is starting to come together. Here is my code now
Private Sub Document_New()

Dim result As Integer
Dim curFont As String
Dim curSize As Integer
Dim newFont As String
Dim newSize As Integer

curFont = ActiveDocument.Characters(1).Font.Name
curSize = ActiveDocument.Characters(1).Font.Size

result = MsgBox("The current font is " & curFont & " at " & curSize & "
point pitch. Do you want to change it?", vbQuestion + vbYesNo)

If result = 6 Then
Dialogs(wdDialogFormatFont).Show
newFont = Dialogs(wdDialogFormatFont).Font
newSize = Dialogs(wdDialogFormatFont).Size

ActiveDocument.Content.Font.Name = newFont
ActiveDocument.Content.Font.Size = newSize


End If
Selection.MoveDown Unit:=wdLine, Count:=1

End Sub

as you can see I am trying to apply the font size the same way I appled the
font name. I am getting an error saying that this method is not supported.
I promise if I you guys get this part working I will not hassel you guys
again today. Thanks in advance.
 
M

Mark Tangard

In many Word dialogs, the label of a value isn't always the
name of the property (sigh). Here, you need to use .Points
instead of .Size in the line that assigns curSize.

Note that the size is NOT a "pitch" as your MsgBox informs.
Pitch means characters per inch, is a fairly useless concept
for proportional fonts, and doesn't correspond to points at
all. (Larger-point fonts have bigger characters, higher-pitch
fonts have smaller characters.) The phrase "12 point pitch"
is both incorrect and potentially embarrassing.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply ONLY to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 
M

Mark Tangard

In those lines you want to use the actual VBA property, not
the quirky dialog value, so in those lines you *do* want to
use .Size.

See a pattern yet? (If you do, tell me what it is!!) ;)
 
D

DWTSG

Yarrrr. Mark, thanks, I do not see any pattern forming, but I guess that
is the fun of it. This code does not work:

Private Sub Document_New()

Dim result As Integer
Dim curFont As String
Dim curSize As Integer
Dim newFont As String
Dim newSize As Integer

curFont = ActiveDocument.Characters(1).Font.Name
curSize = ActiveDocument.Characters(1).Font.Size

result = MsgBox("The current font is " & curFont & " at " & curSize & "
points. Do you want to change it?", vbQuestion + vbYesNo)

If result = 6 Then
Dialogs(wdDialogFormatFont).Show
newFont = Dialogs(wdDialogFormatFont).Font
newSize = Dialogs(wdDialogFormatFont).Pitch

ActiveDocument.Content.Font.Name = newFont
ActiveDocument.Content.Font.Size = newSize

ActiveDocument.Styles("header").Font.Name = newFont
ActiveDocument.Styles("header").Font.Size = newSize
ActiveDocument.Styles("footer").Font.Name = newFont
ActiveDocument.Styles("footer").Font.Size = newSize
End If

Selection.MoveDown Unit:=wdLine, Count:=1

End Sub

I get a "Object does not support this method or Property' error. Am I
barking up the wrong tree? I have a template that has a header, and a
autodate followed by section break. The default font for the template is
courier new. I would like to give the secretaries an option to change that
font and have it apply to the entire document. Is there a better way?
 
J

Jay Freedman

Hi, DWTSG,

Change this line
newSize = Dialogs(wdDialogFormatFont).Pitch

to this:

newSize = Dialogs(wdDialogFormatFont).Points

The error message you quoted is complaining that "Pitch" is not a valid
argument of the FormatFont dialog -- because the proper name is "Points".

Here's how to figure this out for yourself: In the VBA help, go to the
Answer Wizard tab on the left and look for the term "built-in dialog". Some
way down the list, find the topic "Built-in dialog box argument lists" and
click it. Scroll down the topic to find wdDialogFormatFont and the list of
its arguments. "Points" is the first one.
 
D

DWTSG

That works great.....except for one small snag. If I choose Times New Roman
and 13.5, I get Times New Roman 14. But if I go and select the paragraphs
and then format=>font and do the change manually I get 13.5. I have one
user, the user I am making this for who likes 13.5, Do you have a better
idea for how to apply that? thanks again.
 
M

Mark Tangard

DWTSG, here's one other point, to help you pinpoint bugs like
this (i.e., when you get an error that doesn't tell you what
line caused it):

Run the macro again but instead of running it from Word, run it
from the editor by pressing F8 (while your cursor is in the body
of the procedure). This'll run the macro one line at a time, so
you'll be able to see which line it chokes on. (You can also
hover your mouse over parts of the code and see the values of
various items in it -- also a big help.)

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply ONLY to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 
D

DWTSG

Thanks alot guys.
Mark Tangard said:
DWTSG, here's one other point, to help you pinpoint bugs like
this (i.e., when you get an error that doesn't tell you what
line caused it):

Run the macro again but instead of running it from Word, run it
from the editor by pressing F8 (while your cursor is in the body
of the procedure). This'll run the macro one line at a time, so
you'll be able to see which line it chokes on. (You can also
hover your mouse over parts of the code and see the values of
various items in it -- also a big help.)

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply ONLY to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 

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