要將數據從Visual Basic傳輸到Excel,可以使用Excel對象模型和Visual Basic for Applications(VBA)來完成。
以下是一種常見的方法:
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Dim xlWorkbook As Excel.Workbook
Set xlWorkbook = xlApp.Workbooks.Open("C:\path\to\your\workbook.xlsx")
Dim xlWorksheet As Excel.Worksheet
Set xlWorksheet = xlWorkbook.Worksheets("Sheet1")
xlWorksheet.Range("A1").Value = "Hello"
xlWorksheet.Range("B1").Value = "World"
xlWorkbook.Close SaveChanges:=True
xlApp.Quit
Set xlWorksheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
這樣,數據就會從Visual Basic傳輸到Excel工作表中了。請根據實際需要修改路徑、工作表名稱和要寫入的單元格范圍。