Using standard .Net libraries with VBA

前端 未结 2 545
别那么骄傲
别那么骄傲 2021-01-05 07:40

I have successfully been able to run my own .Net code by following the steps posted here Execute .NET 3.0 code from Office 2003

Is there a way to use the standard .N

2条回答
  •  误落风尘
    2021-01-05 08:22

    You should be able to use ComVisible .NET classes in this way. However the GenerateKey and GenerateIV methods don't have a return value. Try:

    Sub Macro1()
       Dim aesImplementation As New RijndaelManaged
    
       aesImplementation.GenerateKey
       Key = aesImplementation.Key
       aesImplementation.GenerateIV
       IV = aesImplementation.IV
    End Sub
    

    or better, not least because when debugging you can see whether an error occurs during construction or when you call the method:

    Sub Macro1()
       Dim aesImplementation As RijndaelManaged
       Set aesImplementation = New RijndaelManaged
    
       aesImplementation.GenerateKey
       Key = aesImplementation.Key
       aesImplementation.GenerateIV
       IV = aesImplementation.IV
    End Sub
    

提交回复
热议问题