Is there a way in VBA to know about variables that aren't being used? [closed]

。_饼干妹妹 提交于 2019-12-21 03:36:11

问题


Is there a tool, method or setting in the standard VBA Editor to warn about variables that have been Dim'med, but aren't being used?


回答1:


MZ-Tools will search through your code and tell you what is not being used. The version for VBA can be found here.

The specific feature in MZ-Tools that performs what you asking about is Review Source Code:

The Review Source Code feature allows you to review the source code to detect some unused declarations (constants, variables, parameters, procedures, etc.).




回答2:


Another method (because I don't have admin privileges to install that software), is to put Option Explicit at the top of your module. Then comment out all the Dim'med variables, and debug through your code with F8 or recompile with Alt+d+l

Uncomment the Dims one by one until Option Explicit returns no compiler errors, at which point any variables still commented out can be ignored, as they are not used in your code


Similar to MZ-Tools, RubberDuck has a VariableNotUsed Inspection (amongst many other things) that should show precisely what you're after. It's free and, as of v2.2.0.3086, it supports non-admin installation.



来源:https://stackoverflow.com/questions/188913/is-there-a-way-in-vba-to-know-about-variables-that-arent-being-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!