Launch the vba editor from excel by code

空扰寡人 提交于 2019-12-24 18:35:03

问题


In Vsto-excel project , i have a macro in a particular module. By code in c#, i want to launch the VBA editor showing the given macro. i know the interop concepts , but i m stuck at launching the vba editor and showing the particular macro.


回答1:


You can use Application.Goto "MarcoName" which will open up the VBE at the sub / macro you specify.




回答2:


The keyboard shortcut ALT + F11 on a open excel sheet ,opens the VBA Editor by default. Use the excel interop to open the excel and make the excel window visible .Then you can pass the keyboard shortcut to the excel window,from your application.

If you are using this on a winform application ,you can use the sendkeys method to pass the keyboard shortcut to the excel window. http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

otherwise use the sendmessage method to pass the keyboard shortcut across.Here is the so post on the sendmessage usage , c# Sending keyboard commands to another window / process.



来源:https://stackoverflow.com/questions/12701783/launch-the-vba-editor-from-excel-by-code

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