vb6.0中,如何将textbox的内容写入到excel中A1单元格内。
vb6.0中,如何将textbox的内容写入到excel中A1单元格内。需要添加部件或dimas……吗?...
vb6.0中,如何将textbox的内容写入到excel中A1单元格内。需要添加部件或dim as ……吗?
展开
3个回答
展开全部
给你一个例子吧
Dim strTemplateFile As String
Dim strFileName As String
Dim FSO As New FileSystemObject
Dim excelApp As Excel.Application
Dim excelBook As Excel.Workbook
Dim excelSheet As Excel.Worksheet
Dim lngLineNo As Long
Dim i As Long
strTemplateFile = App.Path & "\YH_sales.xls"
If Not FSO.FileExists(strTemplateFile) Then
MsgBox "模板文件不存在", vbCritical, Me.Caption
Exit Sub
End If
strFileName = App.Path & "\" & Year(Now) & "-" & Month(Now) & "-" & Day(Now) & "-sales.xls"
If FSO.FileExists(strFileName) Then
FSO.DeleteFile strFileName
End If
Set excelApp = CreateObject("Excel.Application")
Set excelBook = excelApp.Workbooks.Open(strTemplateFile)
Set excelSheet = excelBook.Worksheets(1)
excelApp.Visible = True
excelApp.DisplayAlerts = False '禁止Excel提示
excelApp.Columns("A:L").NumberFormatLocal = "@" '设置成文本格式
excelSheet.Range("C3").Value = Text2.Text
excelSheet.Range("J3").Value = Format(Text73.Text, "0000000")
excelSheet.Range("M3").Value = DateValue(DTPicker1.Value)
Dim totalJE As Double
Dim TotalRow As Integer
totalJE = 0
TotalRow = 0
lngLineNo = 5
For i = 0 To 11
If Combo37(i).Text <> "" And Combo16(i).Text <> "" Then
excelSheet.Cells(lngLineNo, 1) = Combo37(i).Text
excelSheet.Cells(lngLineNo, 4) = Combo16(i).Text
excelSheet.Cells(lngLineNo, 5) = Text25(i).Text
excelSheet.Cells(lngLineNo, 6) = Text13(i).Text
excelSheet.Cells(lngLineNo, 7) = Text37(i).Text
excelSheet.Cells(lngLineNo, 9) = Val(Text13(i).Text) * Val(Text37(i).Text)
excelSheet.Cells(lngLineNo, 10) = "一年"
excelSheet.Cells(lngLineNo, 13) = Text61(i).Text
lngLineNo = lngLineNo + 1
TotalRow = TotalRow + 1
If TotalRow >= 10 Then
MsgBox "本页面最大支持10行数据输入。", vbOKOnly, "提示"
Exit For
End If
End If
Next i
excelBook.Saved = True
excelBook.SaveAs strFileName
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询