Word Automation: Failed to open macro store
My application (vb.net windows application deployed via ClickOnce) uses Word to open and populate .dot templates to create new Word documents. I am linking to Microsoft Word Object Library 14 and using this code:
Dim oWord As Word.Application = Nothing
Dim oDoc As Word.Document = Nothing
Try
oWord = New Word.Application
Dim strFileName As String = ""
Select Case strType
Case "LettreReception"
strFileName = Path.Combine(GetParam(1), "Template_LettreReception.dot")
If File.Exists(strFileName) Then
oDoc = oWord.Documents.Add(strFileName)
On the last line, I get the error " could not open macro save " on deployed computers (not my development machine).
I am developing with Windows 7 - Office 2010 - VS 2010 (.Net 3.5). My deployment machine is also on Windows 7 with Office 2010 installed.
I tried deleting normal.dotm (I found several links that recommend it) with no success. The .dot template used does not contain a macro.
source to share
Because Word Interop actually runs behind the scenes as if it were running in an interactive session, certain permissions are required for the account used at runtime.
Are you using Windows Authentication and Impersonation in your web application? If so, then the user who pretends to work must have local logon rights on the server to run Word ... In addition, you must actually log in to the server with this account at least once in order for this computer to be created. a profile for this user so the registry hive can be loaded. I also found that you may need to actually start Word at least once as this user (to make sure any initialization messages are taken care of the first time before trying to start Word from code).
If not, then the service account that the application is running on (usually NETWORK SERVICE) requires the aforementioned permissions (which I will briefly cover) and you will have to do something like load the dynamic hive dynamically at startup time. Personally, I prefer to implement temporary impersonation in code with a user account that has local server permissions on the corresponding server.
Local log access permissions can be a little tricky depending on your network configuration and Group Policy (if you want to be somewhat secure and not just use a domain admin account).
The reason everything works on your machine running VS is because the web application context is your user account, which of course has local permissions on your machine with a piece of registry to load.
Now for permissions:
-
First you have to run "dcomcnfg" on the server and make the following configuration change:
- Right click on Component Services \ Computers \ My Computer \ DCOM Config \ Microsoft Word 97 - 2003 and go to Properties
- On the Properties screen, go to the Security tab and change the Launch and Activation Permission to Customize.
- Click the "Change" button and add the NETWORK SERVICE account of the local computer (if you are not using impersonation ... If you are using impersonation, add the appropriate user or group) to the user list and check "Local start" and "Local activation"
-
Make sure the NETWORK SERVICE account on the local computer (if not using impersonation ... If using impersonation, the corresponding user or group) has the appropriate read / modify permissions for the folders and file (s) that you open and / or save ...
-
Create a Desktop directory under: C: \ Windows \ System32 \ config \ systemprofile \ and give Full Permissions to the local NETWORK SERVICE account (or the account running the ASP.NET application) [NOTE. I believe this and the next step only apply if you DO NOT use impersonation]
-
Grant Modify / Read / Execute permissions to C: \ Windows \ System32 \ config \ systemprofile
Hope this helps some and not too confusing ...
source to share
"could not open macro store" tells you that VBA is looking for a specific structured storage file, such as .DOT or .DOC, and looks for the store (a kind of stream in the file) in that file that contains the VBA code. If it cannot open it, possible reasons include:
- container (.doc / .dot) does not exist
- container cannot be opened with caller permissions
- there is a container, but the store does not exist (for example, the target system has a container with the expected name, but it does not contain macros)
- the container is there and the storage is there, but cannot be opened with caller permissions
So, you need to take a look at your project looking for everything it references (maybe even other objects or DLLs that you specified with Tools-> References) that are also not delivered with your template.