The Problem (Q-score 8, ranked #14th of 32 in the Word VBA archive)
The scenario as originally posted in 2009
I am trying to edit a word document from VB.NET using for the most part this code:
How to automate Word from Visual Basic .NET to create a new document
http://support.microsoft.com/kb/316383
It works fine on my machine but when i publish to the server i get the following error.
Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.Description: An unhandled exception occurred during the
execution of the current web request.
Please review the stack trace for more
information about the error and where
it originated in the code.Exception Details: System.UnauthorizedAccessException:
Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.
The actual error happens when i try to just create a word application object
Dim oWord As New Word.Application
Using Visual Studio 2008 and VB.NET 3.5. I made a reference to the “Microsoft Word 10.0 Object Library” and i see Interop.Word.dll file in the bin directory.
Using MS Office 2003 on development machine and Windows Server 2003
Still fairly new to .NET and don’t have much knowledge about window server, but “UnauthorizedAccessException” sounds like a permission issue. I’m wondering if someone could point me in the right direction on what i might need to do to give my little application access to use word.
Why community consensus is tight on this one
Across 32 Word VBA entries in the archive, the accepted answer here holds solid answer (above median) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — solid answer (above median) (+7)
Verbal answer — walkthrough without a code block
Note: the verified answer is a prose walkthrough. If you need a runnable sample, check Word VBA entries ranked in the top 10 of the same archive.
It definitely sounds like a permissions problem. Are you running your code in a windows service? The service normally runs as Local System, which may not have permission to access the Word object model. Additionally, if word is already running using the credentials of some other user then your program may not be able to access it via COM using different credentials. The office applications tend to be single instance which seems to exacerbate this problem.
When to Use It — vintage (14+ years old, pre-2013)
Ranked #14th in its category — specialized fit
This pattern sits in the 63% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Word VBA archive for a higher-consensus alternative.
What changed between 2009 and 2026
The answer is 17 years old. The Word VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.