简体   繁体   English

在vba中,可以安全删除与正在运行的宏关联的按钮和工作表吗? (内存不足,无法读取的内容错误)

[英]in vba, can I safely delete buttons and sheets that are associated with the macro that is running? (out of memory, unreadable content errors)

I do not see any immediate errors or problems when I have a macro delete a button (or sheet with a button on it) that is the same button that was used to start the same macro initially. 当我有一个宏删除一个按钮(或带有按钮的工作表)时,我看不到任何立即的错误或问题,该按钮与最初用于启动相同宏的按钮相同。 To be 100% accurate, it is really a sub called within the sub associated with a the button that is actually deleting said button. 为了100%准确,它实际上是与实际上删除了该按钮的按钮相关联的子对象中称为的子对象。

However, I am trying to solve intermittent 'out of memory' and 'unreadable content' errors and disappearing button issues (all in same workbook) with very little success and I am wondering if what I am doing (described above) in vba is some how silently causing these issues later. 但是,我试图解决间歇性的“内存不足”和“内容不可读”错误以及消失的按钮问题(均在同一工作簿中),但收效甚微,我想知道我在vba中所做的(如上所述)是否有些以后如何静默地导致这些问题。

EDIT: I do get a warning immediately when I delete the 'associated button when in break mode, but it only indicates that I can't use break mode after deleting the button. 编辑:当我在中断模式下删除“关联的按钮”时,我确实会立即收到警告,但这仅表示删除按钮后无法使用中断模式。 However, that makes me suspicious. 但是,这使我感到怀疑。

All buttons are ActiveX, but they were Controls. 所有按钮都是ActiveX,但它们是控件。

The workbook is large, but the issue is intermittent, so I don't think that is the issue. 该工作簿很大,但是问题是断断续续的,所以我认为这不是问题。

EDIT: I have already controlled for 'too much stuff open' (not enough memory). 编辑:我已经控制了“太多东西打开”(没有足够的内存)。

This is how I delete the buttons: 这就是删除按钮的方式:

Dim Shp As Shape
For Each Shp In ThisWorkbook.Sheets("Formulas").Shapes
 Shp.Delete
Next Shp

This is how I delete the sheet with the button on it: 这是删除带有按钮的工作表的方式:

ThisWorkbook.Sheets("Formulas").Delete

Please note that the question is asking about a macro 'self-deleting' its own associated button, but I am okay with hearing more about 'out of memory' and 'unreadable content' errors and disappearing button issues generally. 请注意,问题是关于宏“自删除”其自己关联的按钮的问题,但是我可以听到更多有关“内存不足”和“内容不可读”的错误,并且通常会消失的按钮问题。

I have 15 years experience with Excel and VBA, but no formal CS education, so please free to dive in deep with your answers. 我在Excel和VBA方面拥有15年的经验,但是没有接受过正规的CS教育,因此请随时深入了解您的答案。 :) :)

As long as you are completely done using and referring to the buttons themselves, I don't see how deleting them would create any problems. 只要您完全完成了使用和引用按钮本身的操作,我就看不到如何删除它们会造成任何问题。 With the linear nature of VBA, once that button is pressed and the SubRoutine is called, the button would no longer have any ties to the macro (again, as long as there is no other code that in some way points to or refers to the button). 由于VBA具有线性特性,一旦按下该按钮并调用SubRoutine,该按钮将不再与宏有任何联系(同样,只要没有其他以某种方式指向或引用该代码的代码)按钮)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM