Private Sub Command3_Click()Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "dsn=hgsql;uid=sa;pwd=o4w5n6;database=hgprd"
conn.Open
str = "select * from shouli where 受理日期 between " & Trim(Text1.Text) & "and " & Trim(Text2.Text) & "order by 受理日期"
rs.CursorLocation = adUseClient
rs.Open str, conn, adOpenDynamic, adLockOptimistic
Dim strSource, strDestination As StringstrSource = App.Path & "\1.xls"
strDestination = App.Path & "\2.xls"
FileCopy strSource, strDestination
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = FalseSet xlbook = xlapp.Workbooks.Open(strDestination)
Set xlsheet = xlbook.Worksheets(1)
rs.MoveFirst
If IsNull(rs!保单号) = False Then
xlsheet.Cells(1, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(1, 2) = rs!业务员
End If
xlbook.Savexlapp.Quit
End Sub
每次都只能保存第一行的记录,如果将所有的记录全部保存xlsheet.cells()将如何写
Set rs = New ADODB.Recordset
conn.ConnectionString = "dsn=hgsql;uid=sa;pwd=o4w5n6;database=hgprd"
conn.Open
str = "select * from shouli where 受理日期 between " & Trim(Text1.Text) & "and " & Trim(Text2.Text) & "order by 受理日期"
rs.CursorLocation = adUseClient
rs.Open str, conn, adOpenDynamic, adLockOptimistic
Dim strSource, strDestination As StringstrSource = App.Path & "\1.xls"
strDestination = App.Path & "\2.xls"
FileCopy strSource, strDestination
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = FalseSet xlbook = xlapp.Workbooks.Open(strDestination)
Set xlsheet = xlbook.Worksheets(1)
rs.MoveFirst
If IsNull(rs!保单号) = False Then
xlsheet.Cells(1, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(1, 2) = rs!业务员
End If
xlbook.Savexlapp.Quit
End Sub
每次都只能保存第一行的记录,如果将所有的记录全部保存xlsheet.cells()将如何写
解决方案 »
- 无奈-我要做一个界面,这个界面要求能够打开excel文件,然后自动执行其中的VBA程序,不管用什么语言都可以
- 引用EXCEL对象后,EXCEL进程不能删除的问题。
- 当窗体最小化时,触发什么事件?(我需要在窗体最小化时做一些事)
- 菜鸟提个问题:
- VSFlexGrid如何使用,请帮帮忙,急?
- 如何用VB实现对ACCESS数据库中数据的实时更新
- vb时间问题,在线等待,咋办?
- 如何将Picture中的图像转换为图片。
- 如何在启动程序时,把图标放到右下角的任务栏里?
- 请问如何调用打开目录的窗口,就像点击资源管理器的 [复制至]按钮调出的窗口一样
- 高分求救!学校自动排课系统如何做?
- 海到无边天做岸 回答下句送分
Set rs = New ADODB.Recordset
conn.ConnectionString = "dsn=hgsql;uid=sa;pwd=o4w5n6;database=hgprd"
conn.Open
str = "select * from shouli where 受理日期 between " & Trim(Text1.Text) & "and " & Trim(Text2.Text) & "order by 受理日期"
rs.CursorLocation = adUseClient
rs.Open str, conn, adOpenDynamic, adLockOptimistic
Dim strSource, strDestination As StringstrSource = App.Path & "\1.xls"
strDestination = App.Path & "\2.xls"
FileCopy strSource, strDestination
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
dim i as integer
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = FalseSet xlbook = xlapp.Workbooks.Open(strDestination)
Set xlsheet = xlbook.Worksheets(1)
rs.MoveFirst
do while not rs.eof
i=i+1
If IsNull(rs!保单号) = False Then
xlsheet.Cells(i, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(i, 2) = rs!业务员
End If
loopxlbook.Savexlapp.Quit
End Sub
rs.MoveFirst
rs.movelast
N=rs.recordcountfor i =1 to N
If IsNull(rs!保单号) = False Then
xlsheet.Cells(i, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(i, 2) = rs!业务员
End If
next N
i=i+1
If IsNull(rs!保单号) = False Then
xlsheet.Cells(i, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(i, 2) = rs!业务员
End If
rs.MoveNext
loop
rs.MoveFirst
rs.movelast
N=rs.recordcountfor i =1 to N
If IsNull(rs!保单号) = False Then
xlsheet.Cells(i, 1) = rs!保单号
End If
If IsNull(rs!业务员) = False Then
xlsheet.Cells(i, 2) = rs!业务员
End If
next N
错误提示“无效的NEXT空间变量引用”