VB中如何把text中的内容写入指定的Excel中

2024-12-04 08:58:30
推荐回答(2个)
回答1:

应该把命令写在:在TEXT1推动焦点时,进行该命令:
Dim app As Excel.Application
Dim wbk As Excel.Workbook
Dim wsh As Excel.Worksheet

Private Sub Text1_LostFocus()
Set app = CreateObject("excel.Application")
Set wbk = app.Workbooks.Open(Path)
Set wsh = app.Worksheets(1)
wsh.Activate
wsh.Cells(a, b) = Text1.Text
wbk.Close
app.Quit
Set app = Nothing
Set wbk = Nothing
Set wsh = Nothing
End Sub

回答2:

你的问题比较含糊,是不是要把用户窗体上Textbox里的内容写入Excel表格?