我第一次将VBA代码迁移到VSTO,以便为excel创建COM加载项。我能够将所有代码转换为vb。不幸的是,我在VS2017中创建Windows窗体时遇到困难。我试图添加windows窗体,但没有看到任何windows窗体。相反,我只能添加用户控件(WPF)。
我确实使用XAML创建了表单,但最大的问题是如何初始化表单。
进口产品如下
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Windows.Forms
我在下面的代码中看到以下错误
处理MyBase。加载-->找不到事件“Load”
在这之后,我看不到有任何效果。有人能解释一下我们是如何处理加载和卸载用户控件(WPF)的吗。也是我无法导入windows窗体的原因。
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RefSht As Object
Dim TableList() As String
Dim IDTable As String
Dim count As Integer : count = 0
Dim TextBox1 As System.Windows.Controls.TextBox
Dim TextBox2 As System.Windows.Controls.TextBox
Dim TextBox3 As System.Windows.Controls.TextBox
Dim TextBox4 As System.Windows.Controls.TextBox
Dim TextBox5 As System.Windows.Controls.TextBox
Dim TextBox6 As System.Windows.Controls.TextBox
Dim cmbIDTable As System.Windows.Controls.ComboBox
Dim wb As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
RefSht = wb.Worksheets("RefSheet")
On Error Resume Next
IDTable = ReportSheet.Range("IDTable")
TextBox1.Text = ReportSheet.Range("Title")
TextBox2.Text = ReportSheet.Range("Component")
TextBox3.Text = ReportSheet.Range("Selection")
TextBox4.Text = ReportSheet.Range("Parameters")
TextBox5.Text = ReportSheet.Range("Summary")
TextBox6.Text = ReportSheet.Range("Category")
TableList = Split(GetTableListData(), ";")
cmbIDTable.ItemsSource = TableList
While IDTable <> TableList(count)
count = count + 1
End While
cmbIDTable.SelectedItem = count
End Sub