从Excel文件中删除所有VBA模块? [英] Remove all VBA modules from excel file?

查看:751
本文介绍了从Excel文件中删除所有VBA模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用VBA从Excel文件中删除所有VBA模块?

Is it possible to remove all VBA modules from an Excel file using VBA?

在运行此脚本之前,模块的名称是未知数。

The names of the modules if they exist at all are unknowns before running this script.

推荐答案

很明显,你可以。以下代码将执行以下工作:

Obviously, you can. The following code will do the job:

Sub compact_code()

On Error Resume Next
    Dim Element As Object
    For Each Element In ActiveWorkbook.VBProject.VBComponents
        ActiveWorkbook.VBProject.VBComponents.Remove Element
    Next

End Sub

这将删除包括ClassModules和UserForms在内的所有模块,但保留所有对象模块(工作表,工作簿)。

This will remove all modules including ClassModules and UserForms but keep all object modules (sheets, workbook).

这篇关于从Excel文件中删除所有VBA模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆