Office Word Programming >> Programatically changing Default Font in Word 2007

by R1J1c3NlbGw » Thu, 28 May 2009 00:43:03 GMT

Hi,

I'm trying to create a little app that will programatically change the
default font for all of the users in the company, as we'd prefer it not to be
a manual job.

So far I've knocked together a quick VB6 app:


Private Sub Form_Load()
Dim wdApp As New Word.Application
wdApp.Visible = True
Dim wdDoc As Word.Document

wdApp.NormalTemplate.OpenAsDocument

Set wdDoc = wdApp.ActiveDocument

With wdDoc.Styles(wdStyleNormal).Font
.Name = "Franklin Gothic Book"
.Size = 12
End With

wdApp.NormalTemplate.Save
wdApp.NormalTemplate.Saved = True

' wdDoc.Save
wdDoc.Close
wdApp.Quit

End Sub


When the code gets to the NormalTemplate.Save line a message box appears in
the word window which makes no sense:

EOALPHANETOCARABICARABICABJADARABICALALPHA...

Then an error appears saying that it couldn't save the word template.

However it has actually updated it!

Can anyone tell me how to change the font and then save it back to the
default template (normal.dotm).

Thanks!


Office Word Programming >> Programatically changing Default Font in Word 2007

by Doug Robbins - Word MVP » Thu, 28 May 2009 05:33:34 GMT


Instead of

wdApp.NormalTemplate.OpenAsDocument

Set wdDoc = wdApp.ActiveDocument

With wdDoc.Styles(wdStyleNormal).Font
.Name = "Franklin Gothic Book"
.Size = 12
End With

wdApp.NormalTemplate.Save
wdApp.NormalTemplate.Saved = True

Try

Set wdDoc = wdApp.Documents.Open("[user template path]\Normal.dot[m]")
With wdDoc
With .Styles(wdStyleNormal).Font
.Name = "Franklin Gothic Book"
.Size = 12
End With
.Save
.Close
End With

You will need to replace/delete the text in [ ] as appropriate depending on
the OS and Word version.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com






Office Word Programming >> Programatically changing Default Font in Word 2007

by R1J1c3NlbGw » Thu, 28 May 2009 16:14:01 GMT

Hi Doug,

Many thanks for your reply, I've finally got my code working (with your
help!).

I had to change the wddoc.save as this reported that the normal.docm file
was readonly, when it wasn't (this could be an environment thing though).

I used wdapp.NormalTemplate.Save which seems to do the job.

For anyone else who is interested my final code is:

Dim wdApp As New Word.Application
wdApp.Visible = True
Dim wdDoc As Word.Document

wdApp.NormalTemplate.OpenAsDocument

'Replacing user template path with the correct path...
Set wdDoc = wdApp.Documents.Open("[user template path]\Normal.dotm")

With wdDoc.Styles(wdStyleNormal).Font
.Name = "Franklin Gothic Book"
.Size = 12
End With

wdApp.NormalTemplate.Save

'Not sure if I need this...
wdApp.NormalTemplate.Saved = True

wdDoc.Close
wdApp.Quit

Thanks again,

Graham.

"Doug Robbins - Word MVP" wrote:



Similar Threads

1. Change Word default save format programatically

2. problems changing default font in Word 2007

Hi,

I am working on this problem in the context of a state-wide Vista roll-
out.  In a nutshell, using the MS recommended method of changing the
default font isn't working for us (bringing up the font dialog box,
setting your preferred font, then hitting the default button).  This
problem is consistent and repeatable.

I've found that if I use the styles dialog box (Ctrl+Shift+S, modify
button etc) and set it there, I can THEN use the above recommended
method from that point on.

I've worked a long time on this including scouring through Process
Monitor to see if I can isolate write failures to the disk or registry
that are made when a user is trying to set this.

Why does doing it the preferred way matter if the workaround works?

A. It should work
B. It is the way Word help will tell our thousands of users to do it.

I'll list possible variables below.

1. some local computer policies have been modified but I have taken a
look and can't find anything relevant (no group policies are being
pushed by the domain controllers at this time).
2. users are running with only User rights and with UAC off
3. users are logging in with domain accounts (it doesn't matter if I
log in locally with either local admin rights or not).

Thank you in advance for any help.

David

3. Unable to Save Changes to Default Fonts and Paragraphs - Word 2007 - Microsoft Office

4. Unable to change envelope font default in Word 2007

In the "Envelopes and Labels/Envelopes" window I right click on the "delivery 
address" and I select "fonts" -then attempt to change the font to Ariel, 
bold, 16 point, dark blue. I click on the default button and it asks me if I 
want to save to Normal template. When I click YES, it makes the change under 
Labels but not but it does not change the default under Envelopes.

Is this a M/S application error or am I doing something wrong? How do I 
correct this so I can change my envelope delivery address font default? 

5. Can't change default font size - Word 2007 - Word Document management

6. Comments - changing default font in Word 2007

I routinely receive documents for editing that were created in Word
2003 with Times New Roman. I highlight everything and change the font
to Calibri... but when I make corrections, the Comment Balloons still
want to use Times Roman.

I have the feeling I should be changing something under the font hood,
but I've lifted everything and can't find it. Any suggestions on how
to make the underlying font of the document, including Comments,
Calibri would be appreciated.

Thank you.

Don

7. Changing default font in normal.dotx in Word 2007 - Word Document management

8. word 2007 default font won't change

I want new word documents to have arial 11 as the default font and have 
repeatedly tried to change the default font to that but it invariably 
defaults to arial 12 - what can I do about this?