ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: Emily

[Emily 分享]

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-5-18 20:58 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

太好了,收藏

楼主辛苦了,谢谢您

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-7-30 20:47 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

Graphic Game "Cube"

TA的精华主题

TA的得分主题

发表于 2005-7-30 21:29 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Ruler Creator

TA的精华主题

TA的得分主题

发表于 2005-7-30 21:46 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
天啊,真有人将魔方在Excel里做出来了,佩服!

TA的精华主题

TA的得分主题

发表于 2005-8-3 23:38 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
好多阿

TA的精华主题

TA的得分主题

发表于 2005-8-7 19:22 | 显示全部楼层

XL: Limitations of Passing Arrays to Excel Using Automation

Version of Passing Array to Passing Array to Microsoft Excel Worksheet Range Macro (Procedure) ----------------------------------------------------------

5.0 A B,C

7.0 (Excel 95) D E,C,H

8.0 (Excel 97) F G,H

9.0 (Excel 2000) F G,H

Footnotes A:

The maximum number of elements in the array is approximately 6550. If you exceed this limit, you receive one or both of the following error messages: Out of Memory 1005: Unable to set the Value property of the Range class The maximum number of elements in the array that you can pass to Excel using the Excel Transpose function is 4095. If you exceed this limit, you receive the following error message: Run-time error '1004': Transpose method of Application class failed B:

The maximum number of elements in the array is 4095. If you exceed this limit, you may receive the following error message: Run-time error '1004': Run method of Application class failed NOTE: When passing a multidimensional array, you may not receive an error message, but the Excel macro will not run when the total number of elements exceeds 4095.

C:

When defining the array parameter in the Excel macro, it must be defined as a Variant variable or you will receive the following error message when you attempt to run the macro using Automation: Run-time error '1004': Cannot find macro <macro name> For example, suppose the name of your macro in Excel is AcceptArray. Here is an example of how the array must be defined in the Excel macr Public Sub AcceptArray(ByVal myarray As Variant) ' You can pass the parameter either ByVal or ByRef. ' To determine the number of elements in the array, use ' the UBound function. End Sub D:

The maximum number of elements in the array is 5461. If you exceed this limit, you receive one of the following error messages: Run-time error '1004': Transpose method of Application class failed - or - Run-time error '1005': Unable to set the Value property of the Range class E:

The maximum number of elements in the array is 5461. If you exceed this limit, you receive the following error message: Run-time error '1004': Run method of Application class failed F:

The maximum number of elements in the array is limited by available memory or the Excel worksheet maximum size (65536 rows X 256 columns). However, the maximum number of elements in the array that you can pass to Excel using the Excel Transpose function is 5461. If you exceed this limit, you receive the following error message: Run-time error '13': Type Mismatch G:

The maximum number of elements in the array is limited only by available memory. Also, you do not have to define the parameter as a Variant variable in the Excel macro. However, if you want to pass the array ByVal, you must define the parameter as a Variant variable as in the example in footnote C earlier in this article. You will get a run-time error 13, "Type Mismatch" error, if you do not define the variable as a Variant.

H:

When passing an argument ByRef to an out-of-process Automation server, such as Excel, marshalling of the data is done between the Automation controller (or client) and server since they run in separate processes. This means that when an array is passed to Excel using ByRef, a copy of the array is sent to the address space of Excel. After the Excel procedure runs, a copy of the array is passed back to the client. Although this does allow for passing arguments using ByRef to an out-of-process server, it is not very efficient. On the other hand, when using an in-process automation server (a dynamic-link library (DLL)) and you pass an argument ByRef, this is very efficient since no marshalling is done. The server is using the same array in memory as the client. This is possible since the server runs in the same address space as the client.

Because of marshalling with an out-of-process server such as Excel, it is more efficient to pass the array ByVal instead of ByRef. This way, only one copy is passed to Excel and Excel does not have to pass the copy back to the client. To pass an array ByVal to an Excel macro, you must define the parameter in the Excel macro as a Variant variable. See footnote C earlier in this article for an example. Back to the top

Sample Visual Basic Procedures The following sample Microsoft Visual Basic for Applications Sub procedures show how to pass arrays to Excel. The first two procedures show how to populate a range of cells on a worksheet by passing an array to a worksheet range. The third procedure shows how to pass an array to an Excel macro.

The following declarations are used with each example: Option Explicit Private xlApp As Object Private xlBook As Object Private xlSheet As Object Passing a 1-Dimensional Array to a Worksheet Range: Public Sub OneDimension() Const size = 5461 Dim myarray(1 To size) As Integer Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.Worksheets("Sheet1") xlSheet.Cells(1, 1).Resize(size, 1).Value = _ xlApp.Application.Transpose(myarray) End Sub Passing a 2-Dimensional Array to a Worksheet Range: Public Sub TwoDimension() Const size = 2730 Dim myarray(1 To size, 1 To 2) As Integer ' Number of elements = 2730 * 2 = 5460. Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.Worksheets("Sheet1") xlSheet.Cells(1, 1).Resize(size, 2).Value = myarray End Sub Passing an Array as an Argument to an Excel Macr Public Sub RunExcelMacro() Const size = 5461 Dim myarray(1 To size) As Integer Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Open("C:\MyBook.xls") xlApp.Run "AcceptArray", myarray End Sub The AcceptArray procedure within a module inside C:\MyBook.xls resembles the following: Option Explicit

Public Sub AcceptArray(ByVal myarray As Variant) MsgBox "Size of first dimension: " & UBound(myarray, 1) End Sub

TA的精华主题

TA的得分主题

发表于 2005-8-12 20:31 | 显示全部楼层
好东西,收藏先!!!![em02]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-8-17 12:15 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-8-17 12:15 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-8-17 12:15 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Reserved
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-26 17:01 , Processed in 0.044076 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表