将text中动态的数据导入excel表格中
将text中动态的数据导入excel表格中 我是新手 求代码 详细点--------------------编程问答-------------------- text内容是什么?要根据内容才能确定。 --------------------编程问答-------------------- 是 数 字 啊 --------------------编程问答-------------------- 是导入excel一个格子中吗?如果是:
'
先引用对象库:Microsoft Excel 11.0 Object Library--------------------编程问答-------------------- 有5个text 而且是动态数据 一秒钟变化一次 我想一秒钟导入一次 麻烦你给个代码 --------------------编程问答--------------------
Option Explicit
Dim xlExcel As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Private Sub Command1_Click()
On Error GoTo Errhandler
xlExcel.Application.Visible = True
'Me.MousePointer = vbHourglass
Application.DisplayAlerts = False '不提示保存对话框
xlExcel.Workbooks.Add '创建新的工作薄
xlExcel.Workbooks(1).Activate '激活工作薄
Set xlSheet = xlExcel.Workbooks(1).Worksheets("Sheet1") '指定Sheet表
'Set xlSheet = xlBook.Worksheets("Sheet1")
xlSheet.Activate
xlSheet.Columns("A:A").NumberFormatLocal = "@" '设置A列为文本格式。
'或者xlSheet.Range("A").NumberFormatLocal = "@"
xlSheet.Cells(1, 1) = Trim(Text1.Text) '第1行第A列
xlSheet.Columns.EntireColumn.AutoFit '列自适应
'Me.MousePointer = vbDefault
xlBook.SaveAs ("C:\Book1.xls")
Errhandler:
Exit Sub
End Sub
Private Sub Form_Load()
Text1.Text = "34523456357456745674567467467467468678567857857468"
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
xlBook.Close
xlExcel.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlExcel = Nothing
End Sub
'先引用对象库:Microsoft Excel 11.0 Object Library--------------------编程问答-------------------- 首先谢谢你 我想追问一下 我现在能够把5个text中的数值导入excel中了 但是呢 由于数值是一秒钟变化一次(动态的),我下一秒导入的数值就把上一秒的数值覆盖了 这是怎么回事啊?
Option Explicit
Dim xlExcel As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Private Sub Command1_Click()
On Error GoTo Errhandler
xlExcel.Application.Visible = True
'Me.MousePointer = vbHourglass
Application.DisplayAlerts = False '不提示保存对话框
xlExcel.Workbooks.Add '创建新的工作薄
xlExcel.Workbooks(1).Activate '激活工作薄
Set xlSheet = xlExcel.Workbooks(1).Worksheets("Sheet1") '指定Sheet表
'Set xlSheet = xlBook.Worksheets("Sheet1")
xlSheet.Activate
'或者xlSheet.Range("A").NumberFormatLocal = "@"
Timer1.Interval = 1000 '1秒
Timer1.Enabled = True
Errhandler:
Exit Sub
End Sub
Private Sub Form_Load()
Text1.Text = "34523456357456745674567467467467468678567857857468"
Text2.Text = "34523456357456745674567467467467468678567857857324"
Text3.Text = "34523456357456745674567467467467468678567857857890"
Text4.Text = "34523456357456745674567467467467468678567857857213"
Text5.Text = "34523456357456745674567467467467468678567857857456"
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
xlBook.SaveAs "c:\MyBook.xls" ', 39
xlBook.Close
xlExcel.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlExcel = Nothing
End Sub
Private Sub Timer1_Timer() '每秒更新一次
xlSheet.Columns("A:A").NumberFormatLocal = "@" '设置A列为文本格式。
xlSheet.Cells(1, 1) = Text1.Text '第1行第A列
xlSheet.Cells(2, 1) = Text2.Text '第2行第A列
xlSheet.Cells(3, 1) = Text3.Text '第3行第A列
xlSheet.Cells(4, 1) = Text4.Text '第4行第A列
xlSheet.Cells(5, 1) = Text5.Text '第5行第A列
xlSheet.Columns.EntireColumn.AutoFit '列自适应
End Sub
我是想第一秒导入的数值在excel第一行,第二秒导入的数值在第二行 以此类推 。。。。
麻烦你给个代码 谢谢你了 --------------------编程问答-------------------- 除
补充:VB , 控件