An exception is showed when CreateObject("Excel.Application") at run time.
Some times works fine for a short time in the same session, but with code changes the exception occurs in the same session; In most cases, from the first execution with a new session, the exception occurs.
Reviewing various proposed solutions with similar problem, I applied some, for example:
a) Change as automatic in SERVICES: Install ActivateX and restarted
b) C:WINDOWSsystem32>regsvr32 scrrun.dll
c) C:WINDOWSsystem32>sfc /scannow
d) Change project to 32 bits or to 64 bit or Any
but only some times works.
For some reason it fails; or does not exist, or has another location or what is required to instantiate.
From the above it seems to me to be a Visual Studio bug or error at compile time; I work with VS 2022 community and VB.net
I greatly appreciate the help for a definitive solution to this exception.
Private Sub PreparaXLSX()
Dim myApp As Excel.Application
myApp = CreateObject("Excel.Application")
End Sub
System.Exception HResult=0x80131500 Message = Cannot create ActiveX component.
+ TargetSite {System.Object CreateObject(System.String, System.String)}
System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
X Cannot call method System.Reflection.MemberInfo.get_CustomAttributes in this context.
What actions to take for a definitive solution or to eliminate access to
System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
2
Answers
Your suggestion works fine, but if I change my code, the exception occurs again; The problem is intermittent with different solution actions.
I appreciate your support Jiachen.
If you’re using early binding with Interop:
If you’re using late binding without Interop: