我得到了一个包含对函数f(x,y)的引用的Excel文件。该文件不包含宏。我编写了一个具有不同功能的宏,并以.xlsm扩展名保存了它。当我运行新的宏时,我从堆栈空间错误中得到了运行时错误'28'。
这是什么意思,我该如何纠正?有人告诉我我不需要基本的视觉效果即可。这是额外的特殊包装吗?谢谢。
Sub xplusy()
'
' xplusy Macro
' Function f(x,y) f=x+y End Function
'
'
Application.Run "'5_3 Runge-Kutta.xlsm'!xplusy"
Sheets("RK4").Select
Range("C9").Select
Application.Run "'5_3 Runge-Kutta.xlsm'!xplusy"
Range("E8").Select
Application.CommandBars("Help").Visible = False
Application.Goto Reference:="xplusy"
End Sub
答案 0 :(得分:2)
让我们将Sub降低到最基本的水平:
Sub VeryBasic()
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
End Sub
现在,看看代码如何调用自己?如果将其扩展到1级,则会得到以下信息:
Sub VeryBasic()
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
Application.GoTo "Location"
End Sub
将其扩展到2个级别:
Sub VeryBasic()
'Application.Run "VeryBasic"
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
Application.GoTo "Location"
'Application.Run "VeryBasic"
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
'Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.Run "VeryBasic"
Application.GoTo "Location"
Application.GoTo "Location"
Application.GoTo "Location"
End Sub
希望,您会发现此代码将变得越来越大,而无需实际执行任何操作,只是将其自身的另一个副本添加到“堆栈”中即可运行。最终,堆栈将耗尽空间(或者计算机将耗尽内存),并且您将收到Stack overflow错误。
答案 1 :(得分:1)
您正在调用函数SELECT
`e`.`id` AS `event_id`,
`e`.`time_stamp` AS `time_stamp`,
`el`.`latitude` AS `latitude`,
`el`.`longitude` AS `longitude`,
`el`.`time_span` AS `extra`,
`e`.`entity_id` AS `asset_name`,
`el`.`other_id` AS `geozone_id`,
`el`.`group_alias` AS `group_alias`,
`e`.`event_type_id` AS `event_type_id`,
`e`.`entity_type_id` AS `entity_type_id`,
`el`.`some_id` as `some_id`
FROM
(select
`id` AS `event_id`,
`time_stamp` AS `time_stamp`,
`entity_id` AS `asset_name`,
`event_type_id` AS `event_type_id`,
`entity_type_id` AS `entity_type_id`
from
`events`
WHERE
time_stamp >= '2018-01-01'
AND time_stamp <= '2019-06-02'
) AS `e`
JOIN `events_locations` `el` ON `e`.`event_id` = `el`.`event_id`
WHERE
`el`.`other_id` = '1'
GROUP BY
`e`.`event_type_id` ,
`el`.`some_id` ,
`el`.`group_alias`;
,它正在调用函数xplusy()
,后者正在调用函数xplusy()
,后者正在调用函数xplusy()
,... 。
每次调用函数时,其引用都会添加到所谓的xplusy()
中,因此您将使该堆栈超载,并解释错误消息。
在原始文件中,您应该检查宏的名称以及要调用的宏(它们肯定应该不同)。