由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Excel VBA copy recordset 的瓶颈
相关主题
save a VBA macro in excel using vbscript (转载)question about excel and access
[求助] 哪位有Excel Macro VBA 教程一类的电子书啊问一个EXCEL VBA programming的问题。
问个简单的excel insert blank page的问题VBA Excel入门教程
embed excel sheet in a .aspx pageUsing EXCEL VBA to download information from website
Please Help me with this Excel VBA problem //bowanyone recommend a book for "Excel VBA programming"?
Excel VBA protection.VBA问题-怎么从OUTLOOK里面读回信人的名字
Interfacing Microsoft Excel VBA with FORTRAN (转载)question on Excel VBA
正在学excel 中的VBA,我的"编辑"下面怎么没有"定位"?在Excel VBA里面定义global variable。
相关话题的讨论汇总
话题: excel话题: recordset话题: rsdata话题: vba
进入Programming版参与讨论
1 (共1页)
g****j
发帖数: 6
1
最近有一个棘手的project,就快完工了,可是却遇上一个不可逾越的障碍,作了好些
research,好像microsoft目前还没有解决这个问题。
任务很简单,把一个SQL Stored Procedure的return results 放到Excel spreadsheet
。下面是简单的一段code
Set cmdCommand = New ADODB.Command
cmdCommand.ActiveConnection = CurrentProject.Connection
cmdCommand.CommandType = adCmdStoredProc
cmdCommand.CommandText = "strDTPastDue"
Set rsData = New ADODB.Recordset
rsData.Open cmdCommand.Execute
objExcel.ActiveSheet.Range("A5").CopyFromRecordset rsData
一般情况下运行良好,可是只要database的某一个field (text) 太长(超过250char)
e*u
发帖数: 17
2
试试在写入field前把Application.ScreenUpdating设为false。
所有数据都写入后再设成true

spreadsheet

【在 g****j 的大作中提到】
: 最近有一个棘手的project,就快完工了,可是却遇上一个不可逾越的障碍,作了好些
: research,好像microsoft目前还没有解决这个问题。
: 任务很简单,把一个SQL Stored Procedure的return results 放到Excel spreadsheet
: 。下面是简单的一段code
: Set cmdCommand = New ADODB.Command
: cmdCommand.ActiveConnection = CurrentProject.Connection
: cmdCommand.CommandType = adCmdStoredProc
: cmdCommand.CommandText = "strDTPastDue"
: Set rsData = New ADODB.Recordset
: rsData.Open cmdCommand.Execute

g****j
发帖数: 6
3
等一下去办公室试试看,只是不明白次为何解? 自己写的Function 和Microsoft的
CopyFromRecordset的performance 还是有上百倍的差距,不知道MS下了什么料在他们
的build-in function里。
k***g
发帖数: 7244
4
这个问题我以前也遇到过,一个 string 的长度不能超过 911 characters,否则就出
Run-time error '1004' 的错误;
使用 loop 的效率太低,即便是你把 application.screenupdating 设置为 false,也
不能有大的改观;
比较好的 solution 是使用 ActiveSheet.QueryTables.Add 的方式,不会出现 911
character 的限制;
这里有一个 reference: http://groups.google.co.uk/group/microsoft.public.excel.programming/browse_thread/thread/cfe13ba9d1211089/55fe0f8715193b3a?lnk=st&q=&rnum=3&hl=en#55fe0f8715193b3a

spreadsheet

【在 g****j 的大作中提到】
: 最近有一个棘手的project,就快完工了,可是却遇上一个不可逾越的障碍,作了好些
: research,好像microsoft目前还没有解决这个问题。
: 任务很简单,把一个SQL Stored Procedure的return results 放到Excel spreadsheet
: 。下面是简单的一段code
: Set cmdCommand = New ADODB.Command
: cmdCommand.ActiveConnection = CurrentProject.Connection
: cmdCommand.CommandType = adCmdStoredProc
: cmdCommand.CommandText = "strDTPastDue"
: Set rsData = New ADODB.Recordset
: rsData.Open cmdCommand.Execute

g****j
发帖数: 6
5
谢谢楼上的二位大哥了,虽然还是没能完全解决问题,但是也至少找到了突破口,the
problem is Excel 的每个cell不能hold 超过911 char的text, 看来这个限制不好突破
。变通了一下,
create a public function as workaround of CopyFromRecordset,then it works all the way.
Function CopyRecordsetToArray(rsData As ADODB.Recordset) As Variant()
'Create an array where # rows = # records and # columns = # fields
'in the recordset.
Dim TempArray() As Variant
Dim r As Integer, c As Integer
ReDim TempArray(1 To rsData.RecordCount, 1 To rsData.Field
1 (共1页)
进入Programming版参与讨论
相关主题
在Excel VBA里面定义global variable。Please Help me with this Excel VBA problem //bow
VBA新手请教简单EXCEL任务Excel VBA protection.
VB.NET转成VBAInterfacing Microsoft Excel VBA with FORTRAN (转载)
*********VBA Macro 打开 Excel 问题.***********正在学excel 中的VBA,我的"编辑"下面怎么没有"定位"?
save a VBA macro in excel using vbscript (转载)question about excel and access
[求助] 哪位有Excel Macro VBA 教程一类的电子书啊问一个EXCEL VBA programming的问题。
问个简单的excel insert blank page的问题VBA Excel入门教程
embed excel sheet in a .aspx pageUsing EXCEL VBA to download information from website
相关话题的讨论汇总
话题: excel话题: recordset话题: rsdata话题: vba