Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-16
15
Medium Priority
?
252 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:starcontroller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36549364
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...
0
 

Author Comment

by:starcontroller
ID: 36549378
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36549650
If you want to open and work on a template, just treat it as a document.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:starcontroller
ID: 36549668
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36549703
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?
0
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 2000 total points
ID: 36551163
Just open the template (as a template), change the font (and any other attributes you wish) and save it.  I don't see any point in doing this programmatically.  For one thing, it would take much longer.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 36551171
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.
0
 

Author Comment

by:starcontroller
ID: 36551228
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?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36551292
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.
0
 

Author Comment

by:starcontroller
ID: 36551319
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36551645
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
0
 

Author Comment

by:starcontroller
ID: 36569087
I've requested that this question be deleted for the following reason:

No longer needed.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36569088
Losing interest is not an acceptable reason for simply deleting a question.
0
 

Author Closing Comment

by:starcontroller
ID: 36575289
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.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question