I believe I'm being thwarted by a security protocol somewhere, that is blocking certain script requests. Using your example I've changed the script in my ASP page to the following:
Sub OpenDoc(strLocation)
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
objWord.Documents.Open strLocation
objWord.ActiveDocument.Variables("testVar").Value = "testdata"
End Sub
As before my template opens on the click of the button and the AutoOpen macro in the template fires. However when it processes this line (in the template now):
MsgBox ActiveDocument.Variables("testVar").Value
I get the original value of testVar, not the new value passed from ASP. However, if I manually run the AutoOpen macro again, I do see the new value so my ASP script is definitely updating it. This is what must be happening:
objWord.Documents.Open strLocation
<<< AutoOpen macro running here before variable gets updated >>>
objWord.ActiveDocument.Variables("testVar").Value = "testdata"
I have therefore changed the ASP script again as follows:
Sub OpenDoc(strLocation)
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
objWord.Documents.Open strLocation
objWord.ActiveDocument.Variables("testVar").Value = "testdata"
objWord.ActiveDocument.Application.Run MacroName:="refreshVar"
End Sub
The last line here should fire a macro in the template called refreshVar which is exactly the same as AutoOpen. I've tested the code from another Word document and it worked fine. However when I try it in ASP, it breaks the script. When I press the button now, absolutely nothing happens.
Any idea's how I might get round this? I can see two options myself, never of which I favor. The first is to put a button in the template document itself called 'Click here to start' and have that button call my main template macro. Not exactly the elegant solution I'm trying to achieve though. The second option which isn't so bad, is to get all the data I need for the letter and pass it to the template using lots of these commands:
objWord.ActiveDocument.Variables("testVar").Value = "testdata"
which I already know works. And then see if I can refresh the document in my ASP script.
TIA,
Colin
To eMail change cadburyscreamegg.com to colinsteadman.com
[email protected]