Is Automation Broken in A2010

PiedPiper70

Registered User.
Local time
Today, 01:43
Joined
Oct 21, 2012
Messages
115
I have used Automation a lot to programmatically create documents from word templates. This worked fine in Office 2003. It was still fine using A2010 plus Word 2003.

Now I'm trying to upgrade to Word 2010 and I'm getting an issue I don't understand. Here's a simplified code fragment:

Dim wordobj As Word.Application

Set wordobj = CreateObject("Word.Application")
wordobj.Documents.Open "c:\users\dave.k2\desktop\TestTemplate.dotx"
wordobj.ActiveDocument.SaveAs "c:\users\dave.k2\desktop\TestDoc.docx"
wordobj.Quit

I've created a simple Hello World template, the code runs without error but the resulting file won't open, and the error message is - The file Test.docx cannot be opened because there are problems with the contents.

Something's not right but I can't see it for looking. Any ideas please.

Thanks
Dave
 
Are you sure it is not docx instead of dotx?
Code:
wordobj.Documents.Open "c:\users\dave.k2\desktop\TestTemplate.do[COLOR=Red][B]t[/B][/COLOR]x"
 
Yes, I created a .dotx for the purpose of this experiment.

We have hundreds of existing templates in Word 2003 and they are all .dot and when opened they create a .doc. I'm trying to do the same, using the same code, but trying to create a .docx from a .dotx template, and it fails.
 
No. If it was then the error would be "can't find file etc"
 

Users who are viewing this thread

Back
Top Bottom