Can't load xll programmatically

前端 未结 5 490
青春惊慌失措
青春惊慌失措 2021-01-14 12:40

I\'m trying to automating some tests for an Excel add-in, which is in xll form. I have some problem in loading the xll. I\'m writing it in C# and my code looks like this:

5条回答
  •  执笔经年
    2021-01-14 13:13

    I was facing issues with loading user defined function [UDF] in VBA code. Was able to load xll file but wasn't able to call.

    Following code successfully loads XLL files and let's call user defined function from VBA code. There may be redudendent instruction in this module but it works!

    Sub InstallAddIn()
    
    On Error GoTo ErrorHandle
    
    Application.DefaultFilePath = "D:\\MyFolder"
    
    Application.RegisterXLL ("MyXLLFileName.xll")
    
    Set AI = AddIns.Add(Filename:="D:\MyFolder\MyXLLFileName.xll")
    
        If AddIns("MyXLLFileName").Installed Then
           LogInformation ("My XLL is installed")
        Else
           LogInformation ("My XLL is NOT installed")
        End If
    Exit Sub
    
    ErrorHandle:
    
    LogInformation ("------------------------") 'Logging function that I have written. Not a std api
    
    LogInformation (Err.HelpFile)
    
    LogInformation (Err.HelpContext)
    
    LogInformation (Err.Description)
    
    LogInformation ("Error in InstallAddIn module")
    
    LogInformation ("------------------------")
    
    End
    
    End Sub
    

提交回复
热议问题