VBA新手,我错过了一些简单但却一直盯着这一小时的内容:我希望允许用户将另一个CSV输入到已有一些CSV的现有Excel单元格中。下面的代码有效,但有点过于急切:它重复两次字符串,所以如果我之前有5,7,9并且想要添加10,现在说5,7,9,10,5,7, 9,10而不仅仅是5,7,9,10。
我错过了什么?
Private Sub vbKeyReturnSS(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = ChrW(13) Then
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
oExcel = New Excel.Application 'Create a new instance of Excel
oExcel.Workbooks.Open("C:\QA Controller Test Files\" & SelectController.Text & ".xlsm")
oSheet = oExcel.Worksheets(1)
oSheet.Range("B2").Value = oSheet.Range("B2").Value & ", " & TextBox2.Text
oExcel.Visible = True 'Show it to the user
oBook = Nothing 'Disconnect from Excel (let the user take over)
oExcel = Nothing
End If
End Sub