"Run-time error 70: Permission denied" when creating a GUID through Office VBA


 

Symptoms


When you run Visual Basic for Applications (VBA) code that calls the CreateObject("Scriptlet.TypeLib").GUID function to create a GUID in Microsoft Office applications (Word, Excel, etc.,) you receive the following error message:

Run-time error '70':
Permission denied

This problem occurs if one of the following July 2017 security updates for Office is installed:

Status


This issue is by design. In the July 2017 security update, CreateObject("Scriptlet.TypeLib").GUID is blocked for security protection against malicious code in Office VBA.

Workaround


To work around this issue, use one of the following methods.

Workaround 1 (preferred): Use CoCreateGuid 

Instead use the CoCreateGuid Windows API to create GUIDs.

Example

The error occurs when you run the following sample code in Office applications:

Sub GetGUID()
Dim strGuid As String
strGuid = CreateObject("Scriptlet.TypeLib").GUID
MsgBox (strGuid)
End Sub

 

To use the CoCreateGuid function, replace the code with the following code.

Note The replacement code works on both 32-bit and 64-bit Office. See the "Writing code that works on both 32-bit and 64-bit Office" section in 64-Bit Visual Basic for Applications Overview.

Private Type GUID_TYPE
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
 
Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (guid As GUID_TYPE) As LongPtr
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr
 
Function CreateGuidString()
Dim guid As GUID_TYPE
Dim strGuid As String
Dim retValue As LongPtr
Const guidLength As Long = 39 'registry GUID format with null terminator {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
retValue = CoCreateGuid(guid)
If retValue = 0 Then
strGuid = String$(guidLength, vbNullChar)
retValue = StringFromGUID2(guid, StrPtr(strGuid), guidLength)
If retValue = guidLength Then
' valid GUID as a string
CreateGuidString = strGuid
End If
End If
End Function
 
Sub GetGUID()
Dim strGuid As String
strGuid = CreateGuidString()
MsgBox(strGuid)
End Sub
 

Workaround 2 (alternative): Unblock CreateObject(“Scriptlet.TypeLib”).GUID

    To unblock the function, set a registry key that allows the Scriptlet.TypeLib object to instantiate in Office applications. To do this, follow these steps:

    1. Open Registry Editor.
       
      1. Navigate to the following path depending on your Office version and edition.
          32-bit Office 64-bit Office
        Office 2016 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Common\COM Compatibility\{06290BD5-48AA-11D2-8432-006008C3FBFC} HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Common\COM Compatibility\{06290BD5-48AA-11D2-8432-006008C3FBFC}
        Office 2013, Office 2010, Office 2007 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\Common\COM Compatibility\{06290BD5-48AA-11D2-8432-006008C3FBFC} HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Common\COM Compatibility\{06290BD5-48AA-11D2-8432-006008C3FBFC}
        Note If the "COM Compatibility" and "{06290BD5-48AA-11D2-8432-006008C3FBFC}" nodes don't exist, create keys for them.
    2. Create a DWORD (32-bit) value under {06290BD5-48AA-11D2-8432-006008C3FBFC}.
    3. Set the name to ActivationFilterOverride and the value to 1.

      To block the function again, set the value to 0.
    4. Close Registry Editor.
    5. Restart any open Office applications.