怎么把VB中text文本框内的多行数据导入到Excel中?在Excel中可以实现多行数据。
比如,A1存放text中的第一行数据,A2存放text中的第二行数据,A3存放text中的第三行数据。。。依次类推。请大家帮忙。 --------------------编程问答-------------------- 先将text中的文字保存到a.csv文件中,再直接用Excel读该a.csv文件。 --------------------编程问答--------------------
Option Explicit
Dim xlExcel As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Private Sub Command1_Click()
Dim sText() As String, i As Long
sText = Split(Text1.Text, vbCrLf)
xlExcel.Workbooks.Open "D:\Book1.xls" '打开工作薄book1.xls
Set xlBook = xlExcel.Workbooks(1) '设置工作薄1
Set xlSheet = xlExcel.Worksheets(1) '设置sheet表1
xlBook.Sheets(1).Select '选择sheet表1
For i = 0 To UBound(sText)
xlSheet.Cells(i + 1, 1) = sText(i)
Next
xlBook.Save
xlBook.Close
xlExcel.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlExcel = Nothing
End Sub
Private Sub Form_Load()
Text1.Text = "中华人民共和国" & vbCrLf & "中国人民易做图" & vbCrLf & "sdfghsdfghsdfhgsdfhsfdh"
End Sub
补充:VB , 基础类