vb中 如何把textbox中的数据保存到excell中 麻烦要所有代码 谢谢!
2个回答
展开全部
Private Sub 保存文件_Click(Index As Integer)
Dim Cancel As Integer
Dim ExcelApp As Object
Dim x 4 As Integer
Dim MyFileName As String
x = MsgBox("是否保存更改?", vbYesNoCancel + vbExclamation, "VB 保存数据到中 Excel")
If x = 6 Then '单击“是”则保存
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
For x4 = 0 To 10
.Cells(1, x4 ) = Array(text1(x4).text)
Next x4
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
ElseIf x = 7 Then '单击“否”则不保存
Cancel = 0
Else '单击“取消”则不退出程序
Cancel = 1
End If
End Sub
Dim Cancel As Integer
Dim ExcelApp As Object
Dim x 4 As Integer
Dim MyFileName As String
x = MsgBox("是否保存更改?", vbYesNoCancel + vbExclamation, "VB 保存数据到中 Excel")
If x = 6 Then '单击“是”则保存
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
For x4 = 0 To 10
.Cells(1, x4 ) = Array(text1(x4).text)
Next x4
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
ElseIf x = 7 Then '单击“否”则不保存
Cancel = 0
Else '单击“取消”则不退出程序
Cancel = 1
End If
End Sub
展开全部
Private Sub CommandButton1_Click()
With TextBox1
If (Len(Trim(.Text))) = 15 Or (Len(Trim(.Text))) = 18 Then
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = .Text
Else
MsgBox "身份证号码错误,请重新输入!"
End If
.Text = ""
.SetFocus
End With
End Sub
'供参考
With TextBox1
If (Len(Trim(.Text))) = 15 Or (Len(Trim(.Text))) = 18 Then
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = .Text
Else
MsgBox "身份证号码错误,请重新输入!"
End If
.Text = ""
.SetFocus
End With
End Sub
'供参考
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询