Reach ActiveX or Form objects (textbox) from codebehind in an Excel document

后端 未结 5 1490
别跟我提以往
别跟我提以往 2021-01-11 23:43

There are several textboxes in an excel file as ActiveX objects and I want to reach them from codebehind.

I am using ClosedXML for other fields, but I am open for ot

5条回答
  •  花落未央
    2021-01-12 00:21

    You can make file in VBA (in %appdata% folder), and save textboxes value in this file (by example, .ini file).

    And after that open file in C#.

    VBA (.xlsm file)

    '               PtrSafe for 64bit (for 32bit, remove it)
    Private Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
        (ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
        ByVal lpString As Any, ByVal lpFileName As String) As Long
    
    Private Sub TextBox1_Change()
        WritePrivateProfileString "Page1", "TextBox1", TextBox1.Text, "C:\Users\HS\Desktop\exceltab.ini"
    End Sub
    

    C:\Users\HS\Desktop\exceltab.ini

    [Page1]
    TextBox1=ok
    

提交回复
热议问题