1.要先取得 VBIDE 的 GUID(物件的類別識別項) 做法:1、先手動引用 Microsoft Visual Basic for Applications Extensibility 5.3 2、在【信任中心】设置界面中勾选【信任对VBA工程对象模型的访问】 然後執行以下程式碼來列出已引用項目的 GUID 資料 Sub ListReferences() For Each Ref In ThisWorkbook.VBProject.References i = i + 1 Cells(i, 1) = Ref.Name Cells(i, 2) = Ref.GUID Cells(i, 3) = Ref.Major Cells(i, 4) = Ref.Minor Cells(i, 5) = Ref.FullPath Cells(i, 6) = Ref.Description Next Ref End Sub 這樣你就可以取得 Microsoft Visual Basic for Applications Extensibility 5.3 的 GUID 了 2、有了 GUID ,Major,Minor 三個值後,以後要用VBA自動引用Microsoft Visual Basic for Applications Extensibility 5.3 全靠它了 程式碼如下: Sub MakeLibrary() On Error Resume Next 'if it already exits ThisWorkbook.VBProject.References _ .AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3 '版本5.3 End Sub Sub mm() On Error Resume Next 'if it already exits ThisDocument.VBProject.References _ .AddFromGuid "{00020813-0000-0000-C000-000000000046}", 1, 6 ThisDocument.VBProject.References _ .AddFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0 End Sub |
|