开发者

Word 2010 automation with templates

I have written several applications in Delphi which use Word automation. The programs all use templates which are stored in a directory. In pre-2010 versions of Word, one would define the location of the templates in tools|options|file locations; the program开发者_高级运维s would pass the name of the template and Word would know where to find it.

My client has now moved to Office 2010, and as a result, Word cannot find the template when started by my programs. I haven't been able to find a similar dialog box in Word in which I can define the default directory for templates. How does one define such a directory?


Click File | Options | Advanced | File Locations and you get the same dialog as in older verions

Word 2010 automation with templates


Instead of forcing your user to configure Word to define the location of templates, you might prefer to invoke word using /t switch.

/ttemplatename starts Word with a new document based on a template other than the Normal template.

>"%programfiles%\Microsoft Office\Office14\winword.exe" /t"c:\MYTEMPLATES\mytemplate.dotx"


Can't you just specify the full path when creating a new document? Why rely on a settings that possibly can even be changed by the user? Put your templates in your own folder and specify the full path.


Word's paths configuration are stored

You can get the USER template folder via

Word.Application.Options.DefaultFilePath(WdDefaultFilePath.wdUserTemplatesPath)

(there are others options for that property too).

As far as I can tell, the template loading rules haven't changed from 2007 to 2010.

Generally speaking, if your add in needs to load a template, you should specify the FULL path and file name to the template, but you can get the typical user path via the above.

On the other hand, if you install the template into WORD\STARTUP, word will automatically load it. that may not be what you need/want, though.

Finally, if your template doesn't/shouldn't change, it might be better to leave it in your PROGRAM FILES\appname folder and load it from there.

Generally speaking, +requiring+ users to change the FILE LOCATIONS in word (or changing it programmatically) is a bad idea, just because so many people wouldn't have a clue, and those that do definitely DO NOT want addins changing those settings automatically!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜