我一直在尝试添加对特定DLL的引用,经过几次尝试,我发现了一些实际有效的代码。但是,当我尝试使用应该在Excel中工作的DLL进行尝试时,它给我一个错误,并拒绝加载。
我已经使用Excel / Windows随附的一些DLL测试了此代码,但没有任何问题。.想知道是否需要使用新的DLL或类似的东西进行某些“安装”过程。
运行时错误“ 48”
加载DLL时出错
码:
Sub AddReference()
Dim VBAEditor As VBIDE.VBE
Dim vbProj As VBIDE.VBProject
Dim chkRef As Reference
Dim BoolExists As Boolean
Set VBAEditor = Application.VBE
Set vbProj = ActiveWorkbook.VBProject
'~~> Check if "Microsoft VBScript Regular Expressions 5.5" is already added
For Each chkRef In vbProj.References
If chkRef.Name = "VBScript_RegExp_55" Then
BoolExists = True
GoTo CleanUp
End If
Next
vbProj.References.AddFromFile "C:\WINDOWS\system32\HIDDEN.dll"
CleanUp:
If BoolExists = True Then
MsgBox "Reference already exists"
Else
MsgBox "Reference Added Successfully"
End If
Set vbProj = Nothing
Set VBAEditor = Nothing
End Sub
通常,这类问题与Office和正在加载的DLL的位版本冲突有关。
尝试加载正确版本的DLL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句