Automating Word Font Change RRS feed

  • Question

  • Hello all,

    I have a script that can change the font for users - it opens word as a COM object which then lets you set the font, size etc. via cracking open the users normal.dotm (the only way I know to programmatically change the font type/size)

    However the application of the script is unreliable - we will use SCCM to deploy it and the system context seems to be causing some issues....

    Has anyone else had to change the font for Word using a script - Powershell and vb can do it but the method I have tried is not giving me the assurance I need!



    Carl Barrett | Twitter: @Mosquat

    Friday, June 12, 2015 10:38 AM


All replies

  • Not enough information.

    normal.dotx also runs as does

    Every template selected sets its default font.


    Friday, June 12, 2015 11:52 AM
  • yes sorry - didn't have the script to hand - here's some more detail

    $Path = $null
        $Path = Get-ChildItem -Path 'C:\Users' | Where-Object { ($_.PSIsContainer -eq $true)  -and ( $ -like "$UserName*" ) } | Sort-Object CreationTime -Descending | Select-Object name -ExpandProperty name -First 1
        $Path = "C:\Users\" + $Path + "\AppData\Roaming\Microsoft\Templates\Normal.dotm"

    This part above gets the to path to the users normal.dotm - there might be better ways to do this but our issue is not with the above.

      $Word = NEW-Object –comobject Word.Application
      $word.visible = $true

    This sets up the com object

    # Change the Font to Arial 10 for Word 2013
        If (test-path -Path $Path) { 
        $Document = $$Path)
        $selection = $word.selection
        $selection.Font.Name = 'Arial'
        $selection.Font.Size = '54'  #(set to 54 for testing only!)

    And this part takes care of setting the font and size for us.

    The issue is that with the line:

    $Document = $$Path)

    Usually $Document is not set, I guess because word cannot open the path as it has hung.  I have made word.application more reliable but its stil seems that unless you interact with the application (i.e a mouse click on file for example) the $$path) does not work.

    I don't think the issue is PowerShell related, but I'm posting here as maybe someone has a better idea for altering the font this way...perhaps we don't have to use COM?

    Any ideas are appreciated!


    Carl Barrett | Twitter: @Mosquat

    • Edited by Carl_B_ Friday, June 12, 2015 1:05 PM info
    Friday, June 12, 2015 1:04 PM
  • You can configure word via a GPO to use a central template file.  Why would you bother to write a script?


    Friday, June 12, 2015 1:08 PM
  • Your explanation of what is happening doesn't match what happens in a word session.  Office products do not like to be automated in this way so the context can be an issue.

    The open is failing because it is likely that the file is open already or that it is corrupted.


    Friday, June 12, 2015 1:12 PM
  • That sounds good - remember we are trying to alter the default Font and Size for all users - I saw nothing about doing this with GPO (except using GP Preferences to overwrite the existing normal.dotm...which isn't really a great solution)

    If you have any other details then I would appreciate reading them


    Carl Barrett | Twitter: @Mosquat

    Friday, June 12, 2015 1:14 PM
  • Create a corporate template and store it in the shared corporate templates location on the network.  Tell users to use that template to create corp standard documents.

    All corporate documents should be templated and stored in a central folder set.  All Office products are designed to use a central template repository and can be configured to do so via Group Policy.  Stop trying to sneaker-net a fix and use the product as intended.

    Your issue is one of "Business Practices" and training and not a scripting issue.  Scripting will not fix your problem.


    Friday, June 12, 2015 1:18 PM
  • We already use templates. Not every word document a user writes requires a template however and we are trying to ensure that when Word is opened it defaults to a particular font.

    This you would think should be contolled via an admx file but there is nothing for us to use in this scenario. 

    Hence turning to scripting, as most people would when they hit something that they want to overcome.

    What does "stop trying to sneaker-net a fix" mean in this context anyway? 

    Carl Barrett | Twitter: @Mosquat

    Friday, June 12, 2015 1:24 PM
  • So you are trying to force a font on everyone.  That is kind of counter to the point of Word as a "personal" word processor.

    Note that different word versions and OSs will create different issues and that you cannot edit a template when it is open.


    • Proposed as answer by AnnaWYModerator Friday, June 26, 2015 9:58 AM
    • Unproposed as answer by Carl_B_ Friday, June 26, 2015 10:00 AM
    Friday, June 12, 2015 1:49 PM
  • You could also create a project file for word that resets the font each time a new document is created.  Just grab the bew_document event ad reset the font. The user can change it but it will always start with the same default evenm idf they clobber their files.


    • Proposed as answer by AnnaWYModerator Friday, June 26, 2015 9:58 AM
    • Unproposed as answer by Carl_B_ Friday, June 26, 2015 10:00 AM
    Friday, June 12, 2015 2:22 PM
  • No real answers or help with this, decided is perhaps not worth persuing

    Carl Barrett | Twitter: @Mosquat

    • Marked as answer by Carl_B_ Friday, June 26, 2015 10:01 AM
    Friday, June 26, 2015 10:01 AM