Results 1 to 6 of 6

Thread: Change font in MSWord when opening

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    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:
    1. Private Sub Document_Open()
    2.   'set font should be mono spaced
    3.   ActiveDocument.Content.Font.Name = "Curier New"
    4.   'write header
    5.   Selection.TypeText Text:="Some initial text"
    6.   Selection.TypeParagraph 'line feed cr
    7.   Selection.TypeParagraph 'line feed cr
    8. 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:
    1. Selection.Font.Name = "Curier New"
    2.   'or
    3.   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.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    Thanks for your reply.

    Ok, I rewrote the code to see any differences:
    VB Code:
    1. Private Sub Document_Open()
    2.   'set font should be mono spaced
    3.   ActiveDocument.Content.Font.Name = "Curier New"
    4.   'or
    5.   'Selection.Font.Name = "Curier New"
    6.   'or
    7.   'ActiveDocument.Range.Font.Name = "Curier New" 'Lucida Console
    8.   'write header
    9.   Selection.TypeText Text:="QQQQQ"
    10.   Selection.TypeParagraph
    11.   Selection.TypeText Text:="iiiii"
    12.   Selection.TypeParagraph
    13. 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.

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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/

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    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.

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width