You are currently offline, waiting for your internet to reconnect

How to determine whether VBA is enabled for Office applications

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article was previously published under Q285884
This article has been archived. It is offered "as is" and will no longer be updated.
This article discusses how to determine whether Microsoft Visual Basic for Applications (VBA) is installed and enabled for Microsoft Office applications.

How to determine whether VBA is installed

To determine whether VBA is installed, you can call the MsiQueryFeatureState function from the Microsoft Windows Installer API. The following code sample demonstrates how to do this.

Note The code samples in this article were written by using Microsoft Visual Basic 6.0.
Private Declare Function MsiQueryFeatureState Lib "Msi" Alias "MsiQueryFeatureStateA" (ByVal Product As String, ByVal Feature As String) As LongPrivate Sub Command1_Click()   ' Start Word.   Dim wdApp as Object   Set wdApp = CreateObject("Word.Application")    ' Get the Product Code.   Dim szCode as String   szCode = wdApp.ProductCode   ' Get FeatureState for the VBAFiles Feature.   Dim x as Long   x = MsiQueryFeatureState(szCode, "VBAFiles")   If (x = 1) Or (x = 3) Or (x = 4) Then      MsgBox "VBA is installed"   Else      MsgBox "VBA is NOT installed"   End IfEnd Sub				

How to determine whether VBA is enabled

If VBA is installed, it may be disabled. If one of the following DWORD registry keys exists and has a value that is greater than 0, VBA is disabled.
  • Microsoft Office 2003

  • Microsoft Office XP

The following code sample queries these registry keys and then reports whether VBA is disabled for all users, is disabled for the current user only, or is not disabled.
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPrivate Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByVal lpType As Long, lpData As Long, lpcbData As Long) As LongPrivate Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongPrivate Const HKEY_CURRENT_USER = &H80000001Private Const HKEY_LOCAL_MACHINE = &H80000002Private Function VBADisabled(hkeyid As Long) As Boolean    VBADisabled = False        Dim ret As Long    Dim hKey As Long    Dim sKeyName As String    'In the following line, change "10.0" to "11.0" for 2003 versions.    sKeyName = "Software\Microsoft\Office\10.0\Common"    ret = RegOpenKey(hkeyid, sKeyName, hKey)    If ret = 0 Then        Dim dwValue As Long        Dim dwLen As Long        dwLen = 4        ret = RegQueryValueEx(hKey, "VBAOff", 0, 0, dwValue, dwLen)        If ret = 0 Then            If dwValue > 0 Then VBADisabled = True        End If    End If        RegCloseKey hKeyEnd FunctionPrivate Sub Command1_Click()    If VBADisabled(HKEY_LOCAL_MACHINE) Then        MsgBox "VBA disabled for all users"    ElseIf VBADisabled(HKEY_CURRENT_USER) Then        MsgBox "VBA disabled for current user only"    Else        MsgBox "VBA is not disabled"    End IfEnd Sub				
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
287567 Considerations for disabling VBA in Office XP
282847 Some Excel features are unavailable if you disable Visual Basic for Applications and run Excel
145679 How to use the registry API to save and retrieve setting
msi office setup install installer

Article ID: 285884 - Last Review: 12/05/2015 23:59:13 - Revision: 4.2

Microsoft Office Excel 2003, Microsoft Office PowerPoint 2003, Microsoft Office Word 2003, Microsoft Excel 2002 Standard Edition, Microsoft PowerPoint 2002 Standard Edition, Microsoft Word 2002, Microsoft Visual Basic 6.0 Professional Edition

  • kbnosurvey kbarchive kbautomation kbhowto KB285884