This is a limitation of Internet Explorer's Word plug-in. To ensure that all macros in a Word document fire, the generated document should be opened in a separate instance of Word.
There are two solutions to this issue:
- Set WordWriter to instruct the browser to open the document in a new instance of Word. This is an option when using WordWriter in ASP or ASP.NET.
- Instruct the user to save the document to disk and then open it using Word. This is the only option when using WordWriter through Reporting Services.
In either case, the user will first be presented with an Internet Explorer dialog prompting them to Open or Save the document. This cannot be controlled. However, when using WordWriter in ASP or ASP.NET, the behavior when the user clicks Open can be controlled.
Solution 1: Set WordWriter to instruct the browser to open the document in Word
If you are using WordWriter in an ASP or ASP.NET application, you can control this behavior with WordWriter's Save() methods.
The WordTemplate and WordApplication classes both have a parameter called OpenInBrowser which controls whether the generated document will be opened in the Word plug-in within Internet Explorer or whether it will be opened in a new instance of Word.
Method signatures
WordTemplate
ASP.NET: WordTemplate.Save(Response response, string attachmentName, bool openInBrowser)
ASP: WordTemplate.Save(Output As Variant, [optional] attachmentName As String, [optional] OpenInBrowser As Boolean)
WordApplication
ASP.NET: WordApplication.Save(Document doc, HttpResponse response, String fileName, boolean openInBrowser)
Examples
The following examples demonstrate how to have the generated document open in a new instance of Word:
WordTemplate
|
[C#]
|
[VB.NET]
|
[COM/ASP]
|
|
WordTemplate wt = new WordTemplate();
...
wt.Save(Response, "MyDocument.doc", false);
Dim wt As New WordTemplate
...
wt.Save(Response, "MyDocument.doc", False)
Set wt = Server.CreateObject("SoftArtisans.WordTemplate")
...
wt.Save Response, "MyDocument.doc", False
|
WordApplication
|
[C#]
|
[VB.NET]
|
|
WordApplication wApp = new WordApplication();
Document doc = wApp.Open(...);
...
wApp.Save(doc, Response, "MyDocument.doc", false);
Dim wApp As New WordApplication
Dim doc As Document = wApp.Open(...)
...
wApp.Save(doc, Response, "MyDocument.doc", False)
|
Solution 2: Instruct the user to save the document to disk
If you are using WordWriter to deliver a document through Reporting Services, there is currently no way to control how the generated document will be opened. If the user chooses Open when prompted with Internet Explorer, the document will open in the Word browser plug-in. Therefore, to ensure that macros fire, the user should be instructed to first save the document to disk, and then open the document in new instance of Word. The user can do this in one of two ways:
- Run your application as usual. When the Open/Save dialog appears, click the "Save" button and browse to the desired location to save the document to disk.
OR
- If it is a link which generates the document, right-click the link, choose "Save Target As..." and browse to the desired location to save the document to disk.
|