Can a VB app run VBA code within a workbook?

  • First some background on why I'm interested in an answer to the question. I'm employed as a Test Engineer for integrated circuits and the (million+ dollar) machines we use, believe it or not, run on Microsoft Excel. This also means our test programs are written in VBA.


    Typically, I set a breakpoint somewhere in the code, run to that point and try to figure out what the device is doing by reading/writing to it's serial port (all in VBA code). So if I have a function that knows how to get the information I'm looking for called GetTheInfo(), then I would open the Immediate window, type the code, and run it. But if what I needed to run was something like a userform, then I couldn't do that because you cannot run some other set of VBA code if the debugger is "paused".


    So now I'm considering using VB to create the userform and have it call the GetTheInfo() that is buried in the workbook's VBA code. Is this possible? Can A VB application run code that is within an open workbook when Excel's VBA debugger is paused on some line of code?


    I guess another question would be, is it possible to run a userform when the VBA debugger is paused?


    Regards,
    Chris

  • Re: Can a VB app run VBA code within a workbook?


    Chris


    You say you set a breakpoint in the code.


    Where are you setting that breakpoint and how are you selecting where to set it?


    Could you not instead of the breakpoint call another subroutine that does what you want, including displaying a userform if needed?

    Boo!:yikes:

  • Re: Can a VB app run VBA code within a workbook?


    After re-reading my question, it isn't that clear what I'm asking for.


    What I want to be able to do is have a VB application (that I will write) run concurrently with Excel and have the ability for the VB app to run the VBA code that is inside the currently open Excel workbook.


    If that can't be done, then is it possible to have a userform running while stepping through some other VBA code?


    Norie:
    I manually set the break point at some location in the code. When debugging a test, I usually set it on the first line and start from there. As I step through the code I always have to query information from the device. So I perform some bit of code, probe/poke the device to see what happened, rinse/repeat. So what would be great is if I could have a userform that is always running in the foreground that will constantly query the device for me as I step through each line of the test.


    Thanks for the responses,
    Chris

  • Re: Can a VB app run VBA code within a workbook?


    Chris


    I'm afraid it still isn't clear, to me at least what you want.


    Of course you could automate Excel from VB but I'm not sure why you need to.


    Couldn't you use my suggestion of calling another subroutine in VBA?

    Boo!:yikes:

  • Re: Can a VB app run VBA code within a workbook?


    Chris


    I'm sorry but maybe I'm missing something here, breakpoints are intended to be used when developing code for debugging.


    They aren't really meant to be used to allow code execution to stop for, say, user input/intervention.

    Boo!:yikes:

  • Re: Can a VB app run VBA code within a workbook?


    Norie


    You're right, I know. It would just make my life much easier if I *could* run one set of vba code while debugging some other set.


    I'll update this thread if I ever figure out how.


    Regards,
    Chris

  • Re: Can a VB app run VBA code within a workbook?


    Chris


    I'm afraid I'm getting more confused.


    Are you saying that you need/wish to change some code according to some conditions in the existing code?


    Is there any chance of some sample data and some pointers to what you actually want to do?

    Boo!:yikes:

  • Re: Can a VB app run VBA code within a workbook?


    If I understand the question, are you saying you essentially want two identical projects that are running the same code, only you want one to run uninterrupted, while in the other you are stepping through the identical code?


    Even in VB6, you would have to have two seperate IDE windows open in order to do what you are asking.


    If you are wanting to do this, you could copy the workbook, rename it, then open both VBE windows in both workbooks, run the first one, then you can step through the other one. YOu would need two seperate XL windows open, do not open the books in the same application window though.

  • Re: Can a VB app run VBA code within a workbook?


    Bnix,


    You've got it! Using you're method, (ideally) my VB application could spawn a copy of the currently running excel application (including workbook and add-ins) then hide it, and execute it's VBA functions while I'm debugging the original workbook code.


    Now to figure out how to do that...


    Regards,
    Chris