EXCEL VBA Scriptlet.TypeLib Error GUID 365


轉貼:https://support.microsoft.com/zh-tw/help/4036837/run-time-error-70-permission-denied-generate-guid-with-office-vba

「 執行階段錯誤 70: 使用權限被拒 」 建立 GUID,以透過 Office VBA 時


狀況

當您執行 Visual Basic for Applications (VBA) 程式碼時,會呼叫CreateObject("Scriptlet.TypeLib")。GUID函式來建立 GUID,在 Microsoft Office 應用程式 (Word、 Excel,等等) 中您會收到下列錯誤訊息:
Run-time error '70':
Permission denied
如果已安裝下列的年 7 月 2017年安全性更新的 Office,就會發生這個問題:

狀態

這個問題是經過設計規劃。年 7 月 2017年安全性更新, CreateObject("Scriptlet.TypeLib")。GUID被封鎖的 Office VBA 中的惡意程式碼的安全性防護。

因應措施

若要解決這個問題,請使用下列方法之一。

解決方法 1 (建議選項): 使用 CoCreateGuid

請改用CoCreateGuid Windows API建立的 Guid。

範例

當您在 Office 應用程式中執行下列的範例程式碼時,就會發生錯誤:
Sub GetGUID()
Dim strGuid As String
strGuid = CreateObject("Scriptlet.TypeLib").GUID
MsgBox (strGuid)
End Sub

若要使用CoCreateGuid函式,取代下列程式碼中的程式碼。
注意取代程式碼適用於 32 位元和 64 位元的 Office。請參閱64 位元概觀的 Visual Basic for Applications」 撰寫能夠在 32 位元和 64 位元的 Office 程式碼 」 一節。
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
 

因應措施 2 (替代方式): 解除封鎖的 CreateObject("Scriptlet.TypeLib")。GUID

    若要解除封鎖該函式,設定可讓 Office 應用程式中具現化 Scriptlet.TypeLib 物件的登錄機碼。若要執行這項操作,請參考下列步驟:
    1. 開啟 [登錄編輯程式]。
       
      1. 瀏覽至下列路徑取決於您的 Office 版本及版。
         32 位元辦公室64 位元辦公室
        Office 2016HKEY_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 2007HKEY_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}
        附註如果不存在的 「 COM 相容性 」 和 「 {06290BD5-48AA-11D2-8432-006008C3FBFC}"節點,請為它們建立機碼。
    2. 建立下{06290BD5-48AA-11D2-8432-006008C3FBFC}的 DWORD (32 位元) 值。
    3. 設定名稱為ActivationFilterOverride ,並為1的值。

      若要一次封鎖函式,請將值設為0
    4. 關閉登錄編輯程式。
    5. 重新啟動任何開啟的 Office 應用程式。
    內容
    文章識別碼:4036837 - 最後檢閱時間:2017年8月16日 - 修訂: 1
    Microsoft Office 2010 suites, 2007 Microsoft Office suites, Microsoft Office 2016 suites, Microsoft Office 2013 suites, Office 365

    留言

    這個網誌中的熱門文章

    delivery note和delivery order的區別和翻譯

    Eclipse 3.6.1 Helios 中文化方法

    牙技專業英文--技工篇