【发布时间】:2011-01-18 07:35:40
【问题描述】:
我有一组现有的 .net 库,我希望从 Excel VBA 中调用它们(该部分工作正常)。这些库依赖于 app.config 中的设置。我知道我可以在 excel.exe.config 文件中输入这些设置(与 excel.exe 位于同一目录中),但这对我来说似乎不是一个非常易于管理的解决方案,因为我可以看到如果不止一个应用程序想要这样做。
我的问题很简单:COM 公开的 dll 是否有任何方式引用它们各自的配置文件?
示例 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="test" value="Hello world!" />
</appSettings>
</configuration>
示例c#:
namespace ExcelVbaFacingCode
{
public class SimpleAppSettingReader
{
public string GetValue(string key)
{
return ConfigurationManager.AppSettings[key];
}
}
}
VBA 示例:
Public Sub Test()
Dim Test As New SimpleAppSettingReader
Dim sampleValue As String
sampleValue = Test.GetValue("test")
MsgBox "Value: '" + sampleValue + "'", vbOKOnly
End Sub
【问题讨论】:
标签: .net vba com app-config