|
-
Mar 24th, 2003, 05:47 PM
#1
Thread Starter
Hyperactive Member
Change font in MSWord when opening
Hi, I'd like to change the font for a word document (MSWord 2000) when the document is opened. This document will actually be a template (.dot). Here is what I have so far:
VB Code:
Private Sub Document_Open()
'set font should be mono spaced
ActiveDocument.Content.Font.Name = "Curier New"
'write header
Selection.TypeText Text:="Some initial text"
Selection.TypeParagraph 'line feed cr
Selection.TypeParagraph 'line feed cr
End Sub
The problem I'm having is that after the initial text is typed (in the correct font by the way) word seems to revert back to the default font at the insertion point. In other words, when I start typing the document from the keyboard the font used is the default not the font I set up ( in this case Curier New).
I've also tried it this way with the same results:
VB Code:
Selection.Font.Name = "Curier New"
'or
ActiveDocument.Range.Font.Name = "Curier New"
Thanks for any help.
Last edited by JohnVB6; Mar 24th, 2003 at 05:53 PM.
Sometimes what you're looking for is exactly where you left it.
-
Mar 24th, 2003, 06:21 PM
#2
Hi John,
Your code works fine over here - just been playing with this on a MsWord 2000 template & no problems whatsoever after the insertion point I can type with the new font. 
Can you change the font in your code to one of the standard default ones & run this to see if this makes any difference when running?
-
Mar 24th, 2003, 07:47 PM
#3
Thread Starter
Hyperactive Member
Thanks for your reply.
Ok, I rewrote the code to see any differences:
VB Code:
Private Sub Document_Open()
'set font should be mono spaced
ActiveDocument.Content.Font.Name = "Curier New"
'or
'Selection.Font.Name = "Curier New"
'or
'ActiveDocument.Range.Font.Name = "Curier New" 'Lucida Console
'write header
Selection.TypeText Text:="QQQQQ"
Selection.TypeParagraph
Selection.TypeText Text:="iiiii"
Selection.TypeParagraph
End Sub
Now when I open the document the q's and i's print on their own lines but the font is not Curier New even though the toolbar reports the font as Courier New. Courier New should be a mono-spaced font, which means, that the q's and i's will line up perfectly even though the characters are not the same width. Now if I manually select the text and then select Courier New from the drop down menu on the toolbar, the q's and i's change to the correct spacing.
Also, if I change Courier New to Lucida Console the code works fine. Is it possible that even though Courier New is an available font in the drop down menu Word will not recognize it as "Courier New" in my code?
Thanks again.
Sometimes what you're looking for is exactly where you left it.
-
Mar 25th, 2003, 07:25 AM
#4
Okay on this one I admit defeat then, I wondered if there was something up with that particular font & this does seem to be the case though I haven't a clue why.
There may possibly be a way to 're-install' the font into the windows font's folder - I'm not sure if this is a case of moving the file & trying to copy it back into the fonts folder afterward, or whether there are any registry settings you'll need to fiddle with such as the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\ key, but if you need to use courier new here, I would recommend you try asking how to repair or re-install a font on the msdn newsgroups for windows:
http://msdn.microsoft.com/newsgroups/
-
Mar 25th, 2003, 08:34 PM
#5
Thread Starter
Hyperactive Member
I'm sorry I put you through this, it turns out I spelled Courier wrong. Should be "Courier New". Thanks for all your help.
Last edited by JohnVB6; Mar 25th, 2003 at 08:47 PM.
Sometimes what you're looking for is exactly where you left it.
-
Mar 26th, 2003, 04:10 AM
#6
Thank God for that - you're code worked fine over here & couldn't for the life of me figure that one out. No prolems mate - this kinda thing happens to us all!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|