Question

UPDATE 3:

This happens when I have saved the vb6 script, close word, start word, then run the template as you would normally run a template, i.e. strTemplate becomes Normal.doc. Then as soon as I go back to the original template which has not been saved through vsto, that goes back to having Letter.doc in the variable strTemplate...

UPDATE 2:

In my startup script, I have a line as follows:

strTemplate = ActiveDocument.AttachedTemplate

In the original template which is named Letter.dot, strTemplate = Letter.dot.

But for some reason, in the new vsto template which was based on the original Letter.dot template, the same line above becomes Normal.dot, which is causing problems, even thought the new template is still named Letter.dot.

I tried to manually code in

strAttTemplate = "Letter.dot"

and the script gets to the next stage, but then it starts complaining about something else.

So my question is, the original template has strTemplate = Letter.dot, but why does this change to strTemplate = Normal.dot after running the template through vsto?

UPDATE 1:

After running through a debug for both versions of the template, i.e. the original non vsto template, and the new vsto template, I have found out that the original does not have any document properties, but the vsto template has 2 document properties. But that does not seem to be a problem.

It seems that the problem has something to do with the vsto template has normal.dot attached to it, whereas the original non vsto template does not have normal.dot attached to it.

Is it possible to remove attached normal.dot from the new template?

ORIGINAL QUESTION:

I am using Visual Studio 2008 to create a Word 2003 Template project. I select the "use existing template" option which already has some vb6 macro scripting in the background. For some reason, when I save the Visual Studio project, the vb6 scripting stops working.

the old vb6 script runs straight away when the template opens in word, but when i simply use the template in vs2008 without adding extra functionality and save the project and build the project, when i try to open the template in word, the old startup script does not work.

Why is this happening?

Was it helpful?

Solution

The likely scenario is that you have a routine called AutoExec in your Word 2003 .dot VBA. This will not execute when deployed as a VSTO template because it's not the type of add-in Word expects in order to run AutoExec (it expects either .wll files or .dot files in your STARTUP folder). The way around this for VSTO is to use AutoOpen instead which will execute the code in that sub routine when the template is opened as a VSTO add-in.

You can try these three in VBA (in Word, press Alt + F11 to get to the Visual Basic Editor):

Sub AutoNew()
    MsgBox "AutoNew runs when creating a document from a template"
End Sub
Sub AutoOpen()
    MsgBox "AutoOpen runs when opening a template as a document"
End Sub
Sub AutoExec()
    MsgBox "AutoExec runs when loading an add-in (a global template)"
End Sub

The other scenario is you don't have your security settings set to "Low" on your development machine's Word security settings.


Regarding your update #2, this usually happens when you run VSTO in debug mode (F5 instead of compiling and running it Ctrl + F5). Can you confirm how you are running it? If it is neither one of those, is it still normal.dot when you deploy it to a test machine?

Finally, if you could post your full startup script, that would be helpful in determining where the issue may truly lie.

OTHER TIPS

Is it possible the 2003 template is creating a DOCX or a DOTX file, and NOT a DOCM or DOTM file? With 2003 and later, Macro code won't run when it's in a DOCX or DOTX file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top