Checking the values of public variables in Excel VBA - Locals Window Alternative

一个人想着一个人 提交于 2019-12-03 14:35:17

In addition to the Immediate window (as described in the other answer), the Watch window is very helpful in those circumstances. You can activate it in the View menu -> Watch window:

Here you can define:

  • Any variable (e.g. your public variables)
  • A full term, e.g. ActiveWorkbook.UsedRange.Address
  • The scope of each watch
  • Even a breakpoint when the value changes or results in True - this is quite handy when debugging, as it allows you quick conditional breakpoints without adding additional code, e.g. if you set a watch to myVar=0 and active Break When Value Is True, the code will automatically stop the moment the potential bug is "initiated"

You can add all of these options in the "Add watch" dialog, which you either get by right clicking on any variable (or other code) in the code module - or by right clicking in the watch window:

In addition, you can simply edit any watch items in the list by double clicking.

Very handy tool for debugging, esp. in combination with Locals and Immediate windows.

Use Immediate Window. Press Ctrl + G in your coding envoirnment to goto Immediate Window. It allows to get and set the value of your variable when you are in debugging mode. You need to prefix ? to check the value of variable. example

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