Case of the Visual Basic Environment Could Not Be Initialized

Launching Word we got the following error:

image

Clicking Show Help we get some explanations of potential causes:

This error is usually caused by insufficient memory or low disk space. It also occurs when the default Word template (normal.dotm) is corrupt, when the VBE7.DLL file is the wrong version, or when permissions to the TEMP folder on a server share do not allow access to the folder by the user.
Low memory or disk space can be solved by either closing unused applications, removing unused programs or files from your hard drive, or by adding RAM or a larger hard drive. In some cases, a memory leak might have occurred and is exhausting RAM without your knowledge. If you suspect that a memory leak is the problem, shutdown Word and VBA and restart the computer.
Rename the normal.dotm file and then restart Microsoft Word. When you exit Word, Word will build a new normal.dotm file. If you have a backup of normal.dotm, you can replace the defective file by using the backup copy instead of having Word repair the file.
If the VBE7.DLL is not the correct version, replace it.
If your network permissions are insufficient for access to a TEMP folder on a server share, contact the administrator and determine whether the permissions can be changed. If they cannot, redirect VB to use a local TEMP folder.

Machine was not low on disk space, there was no problem accessing temp folder. Repairing office, removing normal.dotm file did not fix the issue.
 

Taking a trace with Rohitab API Monitor (https://chentiangemalc.wordpress.com/category/api-monitor/) I had the following APIs monitored:

  • Component Object Model (COM)
  • Data Access and Storage
  • System Services –> Windows System Information –> Registry
  • Visual C++ Runtime Library –> String Manipulation
  • Windows Application UI Development

From the trace we can search for the error message:

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
256844    10:22:25.620 AM    1    mso.dll    wcsncpy_s ( 0x078bff48, 56, “The Visual Basic environment could not be initialized.”, -1 )    0        0.0000000

Now we can work backwards in log to identify what triggered the error message…

The first errors we came across are registry access errors:

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
83242    5:59:37.126 AM    1    mso.dll    RegOpenKeyExW ( HKEY_LOCAL_MACHINE, “System\CurrentControlSet\Services\EventLog\OAlerts\Microsoft Office 15 Alerts”, 0, KEY_READ | KEY_CREATE_SUB_KEY | KEY_SET_VALUE, 0x0084884c )    ERROR_ACCESS_DENIED    5 = Access is denied.     0.0000713

However I don’t suspect these as we can see later another attempt was made to access key which succeeded:

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
83243    5:59:37.126 AM    1    mso.dll    RegOpenKeyExW ( HKEY_LOCAL_MACHINE, “System\CurrentControlSet\Services\EventLog\OAlerts\Microsoft Office 15 Alerts”, 0, KEY_READ, 0x0084884c )    ERROR_SUCCESS        0.0000213

We then run into this event, which is more interesting:

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
82554    5:59:37.076 AM    1    wwlib.dll    LoadRegTypeLib ( {00020905-0000-0000-c000-000000000046}, 8, 6, 1033, 0x651b2128 )    TYPE_E_LIBNOTREGISTERED    0x8002801d = Library not registered.     0.0001610

The preceding event relates to Visual Basic runtime:

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
82551    5:59:37.076 AM    1    mso.dll    GetFileVersionInfoW ( “C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.DLL”, 0, 2420, 0x08b8aa60 )    TRUE        0.0002327

Looking back further we find event

#    Time of Day    Thread    Module    API    Return Value    Error    Duration
78633    5:59:36.727 AM    1    wwlib.dll    RegisterTypeLib ( 0x089e8848, “C:\Program Files (x86)\Microsoft Office\Office15\MSWORD.OLB”, NULL )    TYPE_E_REGISTRYACCESS    0x8002801c = Error accessing the OLE registry.     0.0004030

The most common issue relating to accessing OLE registry would be lack of permissions. So I run Word as a local Administrator account.

This resulted in the following registry keys and values being added. After this Word was working fine.

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}] [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.6] @="Microsoft Word 15.0 Object Library" [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.6\0] [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.6\0\win32] @="C:\\Program Files (x86)\\Microsoft Office\\Office15\\MSWORD.OLB" [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.6\FLAGS] @="0" [HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.6\HELPDIR] @="C:\\Program Files (x86)\\Microsoft Office\\Office15"

This type of problem could also have been identified with SysInternals ProcMon – but in this case there would be a much larger amount of “false positives” to sort through. In this scenario being able to drill down to event where error message was generated assisted finding root cause much more quickly.

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in API Monitor, Office and tagged . Bookmark the permalink.

6 Responses to Case of the Visual Basic Environment Could Not Be Initialized

  1. Ed says:

    Dear chentiangemale , thank you very much ! By running my MS-Word as local Administrator solves the problem !

  2. jdalrymple01 says:

    chentiangemalc–thank you so much for your tips here. I used your advice to run as administrator, and now Word is working. You are a lifesaver!

  3. It was a nightmare for me to get this resolved until now! Thanks a lot!

  4. Harris says:

    this solution reads like gobble-de-gook to me…I’m an average computer user…this is totally useless…appreciate your effort…however, this is far, far beyond my ability to comprehend.

    • This error can be caused by multiple root causes, so the process here to analyze what causes the issue, targeted at the IT or developer is useful. However if you are lucky you may just try right clicking your office program as “Run As Administrator” one time, see if it eliminates the error. If it does it’s likely permanently fixed.

  5. Max says:

    Cool! Made my day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s