PDA

View Full Version : Comparing AutoCorrects



TonyJollans
12-02-2008, 06:03 PM
Having raised the issue, I'll explain what I'm trying to do.

The background.

If you used Word as Outlook e-mail editor in 2003 or earlier, you just used an instance of Word as you had it elsewhere. This meant that anything in your Normal Template was available both to Word, and to Word-in-Outlook. In particular formatted AutoCorrects; if you created them in either instance, they were available in both.

Using Word as Outlook editor had its problems, and partly because of this, what happens in Office 2007 is that Outlook uses, as its own editor, a cut down instance of Word, kept entirely separate from Word proper. Even if you don't have Word installed, some of its executable ships with Outlook (if you do have Word installed you get a richer feature set, but it still isn't full-blown Word). The new, 2007, Word-in-Outlook uses its own Normal template (NormalEmail.dotm).

As Word and Outlook use separate Normal Templates, formatted AutoCorrects created in one are no longer automatically available in the other. There is no easy way to copy them across, even manually.

What I would like to do.

1. Create a method of programmatically copying AutoCorrects from Word to Outlook.

2. Ideally, automate the process of synchronisation between the two.

The Solution and the Issues.

Although it may be possible to work directly with the XML, I have no idea where to start and have not explored that avenue. That aside (ignoring the limited Word capacity available in Outlook, which I have managed to overcome sufficiently for my needs), the things I need to do are the same in 2003 as in 2007.

The only way to access full details of the AutoCorrects is to insert them into a Document. When that is done, you can extract the content from that Document and create another AutoCorrect from it. Copying from one application to another is possible via the Clipboard (using Copy and Paste) but as a general rule, I don't like using that as it belongs to the User. In Word 2007, you can get a string representation using the WordOpenXML Property of a Range; I haven't tried but I think something similar can be done with the HTMLProject in Word 2003.

So, copying new AutoCorrects from one application to another can be done - relatively easily :). To go a step further, however, I would like to be able to recognise changes as well as just additions and this is where I want to compare them. As far as I can tell, I have a basic process working but I find it very clumsy and I have still to test many scenarios.

I have another issue but it's entirely separate. That is: when you have multiple versions of Word installed on a single machine, how do you invoke a specific version of Word, other than the default. I do have a mechanism but, again, far from perfect.

All comments welcome - apart from the one that says that I clearly have too much time on my hands :)

fumei
12-03-2008, 12:59 PM
"apart from the one that says that I clearly have too much time on my hands "









Darn.

Nelviticus
12-04-2008, 03:00 AM
Hello Tony,

I can't think of any way that you can reliably determine which AutoCorrect entry is the most up-to-date when they're not in sync, because if a user has both Word and Outlook open at the same time and changes an entry there's no way of telling which you should use. If they change something in one app only you can use the file date of the template (once they quit they app), but that won't work if they've changed things in both apps.

Well actually I can think of one way and that's to keep a third 'master list' template with copies of all the AC entries. Compare both apps' entries to that list and if one of the two is different, it's a new entry. However that's pretty clunky and not bullet-proof since (although unlikely) someone could change the same entry in both Word and Outlook to different values, making it impossible to tell which is the latest. I guess you could just say "Word wins" if that happens though.

For something like this have you thought about using Visual Studio Tools for Office instead of VBA? Although harder to get into it is (apparently) more powerful and seems to be the way that Microsoft wants people to go. It might be more of a struggle to start with but anything involving Outlook is hard work anyway.

As for multiple versions of Word, yoinks. If I had to do that I'd try creating a separate mini template for each version I wanted to use, each with the appropriate references, and put all version-specific code in there and call it from my main code. It would be a maintenance headache though so I'm curious about what you've come up with.

Regards

TonyJollans
12-04-2008, 07:45 PM
I determine which is up to date by assuming that, when run from Outlook, the requirement is to synchronise the Outlook version with the Word version - and when run from Word (which is much easier) the intention is to synchronise the Word version with the Outlook version. Not perfect I know, but reasonable I think.

I could try using VSTO but I don't really know how to work well with it - so I don't know what it might make easier.

Multiple versions isn't quite the problem you suggest. The requirement is purely for 2007 but if, as mine is, your default version of Word is 2003, then starting Word by Automation starts 2003 and I don't want that (I need Normal.dotm).

I know two ways, neither entirely satisfactory, to start 2007 when it isn't the default - using Shell or CreateObject("Word.Document.12"). Shell introduces all sorts of complications as it runs asynchronously and doesn't return a useful reference (and you need to pull the path from the registry using some hocus-pocus), so I Create a Document object, from which I can get an Application object - but I have to remember I have done it because closing the document, closes the app as well. As a side note, running multiple instances of 2007 is problematic because the way file locking works in 2007 means that the user is prompted about locked global templates, so it is essential to grab any existing app before trying to start a new one.