VB文本框输入汉字的问题
来源:百度知道 编辑:UC知道 时间:2024/05/18 10:27:46
本人实在不懂。
在网上下载一段VB文本框输出到excel的代码
代码如下:
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入数字。"
Text1.SetFocus
Exit Sub
End If
Dim Row As Long
Dim ExlApp As Object
Dim ExlBook As Object
Dim ExlSheet As Object
Set ExlApp = CreateObject("Excel.Application")
Set ExlBook = ExlApp.WorkBooks.Open("D:\md.xls")
Set ExlSheet = ExlBook.WorkSheets(1)
Row = 1
Do Until ExlSheet.Cells(Row, 1).Text = ""
Row = Row + 1
Loop
ExlSheet.Cells(Row, 1).Value = Val(Text1.Text)
ExlApp.DisplayAlerts = False
ExlApp.Save
ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing
MsgBox "保存成功"
E
在网上下载一段VB文本框输出到excel的代码
代码如下:
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入数字。"
Text1.SetFocus
Exit Sub
End If
Dim Row As Long
Dim ExlApp As Object
Dim ExlBook As Object
Dim ExlSheet As Object
Set ExlApp = CreateObject("Excel.Application")
Set ExlBook = ExlApp.WorkBooks.Open("D:\md.xls")
Set ExlSheet = ExlBook.WorkSheets(1)
Row = 1
Do Until ExlSheet.Cells(Row, 1).Text = ""
Row = Row + 1
Loop
ExlSheet.Cells(Row, 1).Value = Val(Text1.Text)
ExlApp.DisplayAlerts = False
ExlApp.Save
ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing
MsgBox "保存成功"
E
添加一个文本框Text2,代码修改如下:
Private Sub Command1_Click()
Dim Row As Long
Dim ExlApp As Object
Dim ExlBook As Object
Dim ExlSheet As Object
Set ExlApp = CreateObject("Excel.Application")
Set ExlBook = ExlApp.WorkBooks.Open("D:\md.xls")
Set ExlSheet = ExlBook.WorkSheets(1)
Row = 1
Do Until ExlSheet.cells(Row, 1).Text = ""
Row = Row + 1
Loop
ExlSheet.cells(Row, 1).Value = Text1.Text
ExlSheet.cells(Row + 1, 1).Value = Text2.Text
ExlApp.DisplayAlerts = False
ExlApp.Save
ExlApp.Quit
Set ExlSheet = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing
MsgBox "保存成功"
Text1.Text = ""
Text2.Text = ""
End Sub