locked
Can I compile VBA code from excel?

    Question

  • My boss has used VBA in excel to create an application and we have had problems deploying the application to various PCs.  Errors occur during the execution and we have to address dll inconsistancies between PCs to make it run.

    I have heard that it is possible to compile the VBA code with VB.net.  If true, how?


    Joy
    Saturday, May 07, 2011 1:01 PM

Answers

  • No VBA is not compiled and cannot be just compiled in VB.NET without reworking your code.

    It is however possible to implement similar functionality in VB.NET due to the interop functionality and the code may look similar but it will involve reworking the code to .NET to compile using VB.NET

    Saturday, May 07, 2011 4:49 PM
  • My boss has used VBA in excel to create an application and we have had problems deploying the application to various PCs. Errors occur during the execution and we have to address dll inconsistancies between PCs to make it run.

    I have heard that it is possible to compile the VBA code with VB.net. If true, how?

    Hi,

     

    Although, the exception handler in VBA is not powerful as in VS, VBA has its own debug tool and error handler system, which is different with VS.

    Please have a look at this VBA error handling overview:

    http://msdn.microsoft.com/en-us/library/aa690560(v=vs.71).aspx

    Whether you are handling errors in VBA or in script behind an HTML page, there are two basic tools you can use. One is the On Error statement, which you use to "enable" error handling in a procedure. The other is the Err object, which contains information about an error that has already occurred.

     

    See this KB article:

    How to Use "On Error" to Handle Errors in a Macro

     

    Also in this KB article, a lot of error codes are listed to help you identify which error occurs.

    Error Trapping with Visual Basic for Applications

     

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 09, 2011 2:55 AM

All replies

  • No VBA is not compiled and cannot be just compiled in VB.NET without reworking your code.

    It is however possible to implement similar functionality in VB.NET due to the interop functionality and the code may look similar but it will involve reworking the code to .NET to compile using VB.NET

    Saturday, May 07, 2011 4:49 PM
  • Hi,

    A first step would be to find out the root cause of this inconsistencies. Is this because the same version of Excel is not installed everywhere ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Saturday, May 07, 2011 6:18 PM
  • My boss has used VBA in excel to create an application and we have had problems deploying the application to various PCs. Errors occur during the execution and we have to address dll inconsistancies between PCs to make it run.

    I have heard that it is possible to compile the VBA code with VB.net. If true, how?

    Hi,

     

    Although, the exception handler in VBA is not powerful as in VS, VBA has its own debug tool and error handler system, which is different with VS.

    Please have a look at this VBA error handling overview:

    http://msdn.microsoft.com/en-us/library/aa690560(v=vs.71).aspx

    Whether you are handling errors in VBA or in script behind an HTML page, there are two basic tools you can use. One is the On Error statement, which you use to "enable" error handling in a procedure. The other is the Err object, which contains information about an error that has already occurred.

     

    See this KB article:

    How to Use "On Error" to Handle Errors in a Macro

     

    Also in this KB article, a lot of error codes are listed to help you identify which error occurs.

    Error Trapping with Visual Basic for Applications

     

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 09, 2011 2:55 AM
  • Hi,

     

    Have you solved your problem? Does the information above helpful?

     

    I look forward to hearing of you soon.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 12, 2011 11:43 AM