ワークブックの VBA プロジェクトへのライブラリ参照を追加する
Contents
[
Hide
]
場合によっては、コードを使用してライブラリ参照を VBA プロジェクトに追加または登録する必要があります。 Aspose.Cellsを使用して行うことができますVbaProject.References.AddRegisteredReference()方法。
Microsoft Excel の VBA プロジェクトへのライブラリ参照を追加します。
Microsoft Excel では、**ツール > 参照…**手動で。
Aspose.Cells を使用して、ブック内の VBA プロジェクトへのライブラリ参照を追加します。
次のサンプル コードは、ワークブックの VBA プロジェクトに 2 つのライブラリ参照を追加または登録します。VbaProject.References.AddRegisteredReference()方法。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string outputPath = dataDir + "Output_out.xlsm"; | |
Workbook workbook = new Workbook(); | |
VbaProject vbaProj = workbook.VbaProject; | |
vbaProj.References.AddRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation"); | |
vbaProj.References.AddRegisteredReference("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library"); | |
workbook.Save(outputPath); |