以下代码可实现要求:
Dim app As New Excel.Application'定义app为Excel应用程序
Dim book As Excel.Workbook'定义book为的工作簿
Dim sheet As Excel.Worksheet’定义sheet为的工作表
Private Sub Command1_Click()'点击command1按钮实现导入
Set book = app.Workbooks.Add'新建book
Set sheet = book.Sheets(1)'新建sheets(1)
sheet.Range("A1").Value = Text1.Text'sheets(1)中A1赋值为text1内容
sheet.Range("B1").Value = Text2.Text'sheets(1)中B1赋值为text2内容
End Sub
如果几个文本文件之间有对应关系,那么要把所有文件中的内容分别读到几个数组中,
在EXCEL里先以某个字段(如姓名)输出第一列,再到其他数组中去筛选对应的记录,再输出至第二列
如此反复
Dim app As New Excel.Application
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet
Private Sub Command1_Click()
Set book = app.Workbooks.Add
Set sheet = book.Sheets(1)
sheet.Range("A1").Value = Text1.Text
sheet.Range("B1").Value = Text2.Text
sheet.Range("C1").Value = Text3.Text
End Sub