vb中运行vba代码
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't interested in and/or not all of the procedures that led up to arriving at the break point. Adding
当试图找出VBA或VB6中的问题的原因时,了解在错误发生之前执行了哪些过程通常很有价值。 您可以为此使用调用堆栈,但是它通常不足,因为它可能显示您不感兴趣的过程和/或不是导致到达断点的所有过程。 新增中
Debug.Print statements or MsgBox statements in procedures is another way but adding them manually can be very tedious. The add-in I've attached resolves those problems by automatically adding statements in all selected procedures that contains "Debug.Print" or whatever else you want along with the name of the procedure.
过程中的Debug.Print语句或MsgBox语句是另一种方法,但是手动添加它们可能非常繁琐。 我随附的外接程序通过自动添加来解决这些问题 所有选定过程中包含“ Debug.Print”或任何其他所需语句以及过程名称的语句。
When the add-in is loaded this toolbar will be added to the Visual Basic IDE in VB6 or the VBE (Visual Basic Environment) in Excel.
加载加载项后,此工具栏将被添加到VB6中的Visual Basic IDE或Excel中的VBE(Visual Basic环境)中。
![Insert-Procedure-Names-Toolbar.jpg](https://i-blog.csdnimg.cn/blog_migrate/a0889fe93c84245676815c06328dd334.png)
![Choose-Code.jpg](https://i-blog.csdnimg.cn/blog_migrate/90269df83aabe5eef4c8516ad11e7016.png)
And this shows the VB6 version of the window that appears if you click the first button in the toolbar. You use it to select the procedures to be modified. (The VBA version uses different icons which match those that are used in Excel.) In this case shown below all the procedures in frmMain will have the statements added to them but I could have chosen any or all procedures in any or all modules. Had the statements been previously added, the 'Remove' button would have been enabled and clicking it would remove the added statements from your program.
这显示了您单击工具栏中的第一个按钮时出现的窗口的VB6版本。 您可以使用它来选择要修改的过程。 (VBA版本使用与Excel中使用的图标相匹配的不同图标。)在这种情况下,如下所示,frmMain中的所有过程都将添加语句,但是我可以在任何或所有模块中选择任何或所有过程。 如果先前已添加语句,则将已启用“删除”按钮,单击该按钮将从程序中删除添加的语句。
![Insert-Procedures-VB6.jpg](https://i-blog.csdnimg.cn/blog_migrate/bd3eeae0a8df2ae0bceceecc345ad887.png)
Installing the Add-Ins
安装加载项
VB6 VB6Download the InsertProcNameVB6.txt attachment and change the name to InsertProcNameVB6.dll. It doesn't matter where you store it. Once you have the file renamed you need to register the dll. To do that go to Start|Run and enter regsvr32 C:\InsertProcNameVB6.dll on the 'Open:' line and press OK. You should get a message saying that the registration was successful.
下载InsertProcNameVB6.txt附件,并将名称更改为InsertProcNameVB6。 dll文件 。 存放在哪里都无所谓。 将文件重命名后,您需要注册dll。 为此,请转到“开始” |“运行”,然后在“打开:”行上输入
InsertProcNameVB6.txt InsertProcNameVB6.txtThe final step is to go to the VB6 IDE and select the Add-Ins|Add-In Manager… menu item and select 'Insert Procedure Names VB6' from the list. Under 'Load Behavior' I suggest selecting both available options.
最后一步是转到VB6 IDE,然后选择“
Excel 电子表格Download the InsertProcNameVBA.txt attachment and change the name to InsertProcNameVBA.dll. It doesn't matter where you store it. Once you have the file renamed you need to register the dll. To do that go to Start|Run and enter regsvr32 C:\InsertProcNameVBA.dll on the 'Open:' line and press OK. You should get a message saying that the registration was successful.
下载InsertProcNameVBA.txt附件,并将名称更改为InsertProcNameVBA。 dll文件 。 存放在哪里都无所谓。 将文件重命名后,您需要注册dll。 为此,请转到“开始” |“运行”,
InsertProcNameVBA.txt InsertProcNameVBA.txtThe final step is to go to the Excel VBE and select the Add-Ins|Add-In Manager… menu item and select 'Insert Procedure Names VBA' from the list. Under 'Load Behavior' I suggest selecting both available options.
最后一步是转到Excel VBE,然后选择“
Note that while this is a COM add-in you won't see it listed if you go to either File|Options|Add-Ins|COM Add-Ins (or Excel Add-ins).
请注意,尽管这是一个COM加载项,但是如果您转到File | Options | Add-Ins | COM加载项(或Excel加载项),则不会看到它的列出。
If you are interested in learning more about debugging VBA or VB6 code then see my Using the VB6 Debugger tutorial.
如果您想了解有关调试VBA或VB6代码的更多信息,请参阅我的使用VB6调试器教程。
Finally, if you find that this article has been helpful, please click the “thumb’s up” button below. Doing so lets me know what is valuable for EE members and provides direction for future articles. It also provides me with positive feedback in the form of a few points. Thanks!
最后,如果您发现本文对您有所帮助,请单击下面的“竖起大拇指”按钮。 这样做可以让我知道对EE成员有价值的内容,并为以后的文章提供指导。 它还以几点的形式为我提供了积极的反馈。 谢谢!
vb中运行vba代码