Link to home
Start Free TrialLog in
Avatar of starcontroller
starcontrollerFlag for Canada

asked on

How do I open a Word template and get and set the font pragmatically in C#?

I was wondering how to open a dot/dotm file such as Normal.dot, retrieve the default font and set it through C#.

I know that there is Microsoft.Office.Interop.Template but I cannot seem to get it to open a specific template file.
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Why are you opening a template file at all?  I should think that you would be creating a new file using your desired template, which is a different thing entirely...
Avatar of starcontroller

ASKER

I'd like to be able to change the default font so that any future documents created from that template would also have the changed font type and size.
If you want to open and work on a template, just treat it as a document.
I'm trying to create an app that can do this without requiring the user to do it manually by opening word themselves.  I know that I can open Word using Word.Application, but I'd rather have the program do it rather than instructing many users to do this.
It isn't clear what difficulty you are having. You say (I think) that you know how to open the Word application programatically. Can you also open a document?
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For another thing, Normal.dot is highly likely to be in use, so you would not be able to modify it programmatically.  Better to go online (maybe using GoToAssist), make sure all Word instances are closed, then open and modify Normal.dot, and save it.
I just need to create a GUI application that will edit the default font for a template so that GoToAssist is required and I don't need to be directly involved.

I mean, if someone can print text to a document, fonts can be manupulated too, can't they?
Absolutely. Though you may be confused by some a difference in emphasis between Helen and me, we still do not understand what the question is.

Incidentally, though we know how to program the Word Object model, I, at least, do not have C#, which is what I haven't actually posted any code. If you want I'll post some 'legacy' VB code. Any .Net code would be rather more complicated.
I would like to have a program that opens a template file.  The user does not necessarily have to see it open.  The font name is stored in a string and the size is stored in an integer.  There will be two pull-down menus: One for font name and the other for size.  There will also be a save button that will save these changes so future documents with this template would have the font changes.

If you could share any C# code, it might be helpful.

Thanks.
You seemed to indicate in your comment #36549668 that you know how open Word programatically. Are you saying that you don't know how to start writing a C# program to do that? If so here are some links:

This one from Microsoft:
http://support.microsoft.com/kb/316384

And this from a C# specialist forum:
http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
I've requested that this question be deleted for the following reason:

No longer needed.
Losing interest is not an acceptable reason for simply deleting a question.
I decided to go through this approach to save development time.  In addition, I instructed people to close word and I copied over the new templates to their computers to make the updates.