1
votes

I need some advice on how to go about a particular issue I'm trying to build a work around for, but keep finding myself between a couple of poor options.. The application has a large collection of word doc templates. The application is to on the fly generate one of the templates and fill in the bookmarked values.

I have a few options on how to go about this...

Use the Interop Library: I pretty easily fill in an actual, templated document with the Interop library by going through and grabbing all the bookmarks and filling them in and saving the document again.

Issue: I need to be able to support version of Word from 2003-2010; version becomes a concern here... if I link against the wrong version of the Interop.Word, might it cause compatibility issues for users of older versions? I don't have much to test with here, so I'm not sure...

VBA Macro: I've actually used this method to build excel spreadsheets before; write fields to a csv, read into a new document generated from template via VBA, and ta-da, new document.

Issue: Security settings on end-user PCs are likely to be extremely strict. VBA likely to be disabled.

Is there a better way of going about this that I'm not seeing? Is the Interop version likely to be less of a big deal than I thought? Other than OfficeXML, which is a catastrophe for the documents we're using (I've looked..), is there another good possibility?

Edit: submitted early.. damn browser -_-;

1

1 Answers

0
votes

VBA is usually blocked in documents and templates that are opened. But templates in the Word startup directory are allowed. I'm not sure about Word 2007 and 2010, but in Words 97 to 2003 there was a wrdstart directory that could contain templates that were loaded on startup of word. The normal.dot file was in there, and you could add your own to contain scripts, macros toolbars and other stuff.

I think this hasn't changed in essence since then, although I don't do a lot of Word development anymore, so I'm not sure.

[edit]

Yes, it still exists. In Word 2010 you'll find the setting in File -> Options -> Advanced -> File Locations (button). There is a 'Startup' setting, pointing to a directory. Templates in this folder will be loaded on startup and their macro's should be able to be executed.

Check File -> Options -> Trust Center -> Trust Center Settings (button). There, you can specify allowed documents, and trusted location. The wrdstart directory is in there, but you can add your own.