MicroStation Add-in for saving Excel file

Hello Guys,

I'm trying to save an Excel File using a Key-in in MicroStation. I'm revising the codes created by someone and I want to know how this dialog box appears?

 

I want to know also on how I could catch the user's response for this.

I'm sure he's not utilizing another form for this.

 

Best Regards,

Jedrick

Parents
  • Unknown said:
    I'm trying to save an Excel File using a Key-in in MicroStation

    MicroStation doesn't have built-in support for Excel.  The code must either be calling the Excel COM object (i.e.VBA in Excel) or a third-party plug-in that provides Excel compatibility.

    We can't guess.  You must supply sufficient and accurate information.

     
    Regards, Jon Summers
    LA Solutions

  • The title of a dialog box almost always provides some information as to what application or code an operation currently resides in.  As Jon points out, Bentley MicroStation does not host this dialog box (or functionality) natively.  However your MicroStation VBA project code (.mvba file) may be referencing (Tools > References...) a Microsoft COM Excel Object library. e.g. "Microsoft Excel 14.0 Object Library".  To find out "where" the appropriate code may be, open the suspected application's (e.g. MicroStation) VBA Editor (Alt+F11).  Click F2 to open the Microsoft Object Browser then perform a search (across all object libraries - default) and search for a keyword of interest.  e.g. "Save" in the (bottom of the two) text field.

    Then narrow down the list of displayed results by selecting the object library (top of the two) filter by selecting e.g. "Excel".  That will provide you a list of candidate objects, methods, events, and/or properties to explore.  Then perform a full search (Ctrl+F) of the "Current Project" for each VBAProject listed in the (left hand side) VBA Project Explorer.  Although this may take awhile, it is necessary if you do not know the code well enough to debug (Debug > Step Into) the project code in the Microsoft VBA Editor.

    HTH,

    Bob



Reply
  • The title of a dialog box almost always provides some information as to what application or code an operation currently resides in.  As Jon points out, Bentley MicroStation does not host this dialog box (or functionality) natively.  However your MicroStation VBA project code (.mvba file) may be referencing (Tools > References...) a Microsoft COM Excel Object library. e.g. "Microsoft Excel 14.0 Object Library".  To find out "where" the appropriate code may be, open the suspected application's (e.g. MicroStation) VBA Editor (Alt+F11).  Click F2 to open the Microsoft Object Browser then perform a search (across all object libraries - default) and search for a keyword of interest.  e.g. "Save" in the (bottom of the two) text field.

    Then narrow down the list of displayed results by selecting the object library (top of the two) filter by selecting e.g. "Excel".  That will provide you a list of candidate objects, methods, events, and/or properties to explore.  Then perform a full search (Ctrl+F) of the "Current Project" for each VBAProject listed in the (left hand side) VBA Project Explorer.  Although this may take awhile, it is necessary if you do not know the code well enough to debug (Debug > Step Into) the project code in the Microsoft VBA Editor.

    HTH,

    Bob



Children
  • Sorry for the lack of information guys. I'm using Visual C# as the programming language.

    Here is a piece of the code used in saving the file to Excel.

     

     

    After the code (the one specified as breakpoint), the program will detect an error, and debugging will then jump to the catch function. Then in the highlighted code,"if (xl_WS_Tmpl !=null)", the dialog I specified at the start of this conversation pops up. How did that come to be?

     

    BTW, these are the data types of the different codes used.

    Microsoft.Office.Interop.Excel.Application xlApp=null;

    Microsoft.Office.Interop.Excel.Workbook xlWB_Tmpl=null;

    Microsoft.Office.Interop.Excel.Workbook xlWB_Dwg = null;

    Microsoft.Office.Interop.Excel.Worksheet xlWS_Tmpl=null;

    Microsoft.Office.Interop.Excel.Worksheet xlWS_Dwg = null;

     

    Please help me on this one guys. I'm thinking of two options, it's either not to display that dialog box and save the codes to an (.xls) file directly or to display a SaveFileDialog.

     

    Best Regards,

    Jedrick

  • The code you've shown us relates to Microsoft Excel and its COM interface.

    What is property Excel.Worksheet.CheckCompatibility?  Does that property exist in the version of Excel you are using?

    Something makes me suspicious is the variable name xlWB_Dwg.  There may be code that assumes an AutoCAD (DWG) host rather than a MicroStation host.

    Hint: When dealing with problems in a COM interface, it's often a good idea to copy the code to a VBA module in the relevant application (in your case, Excel).  The reason to do that is to eliminate problems that occur because of language differences between VBA and C# that can cause unexpected & incomprehensible errors.

     
    Regards, Jon Summers
    LA Solutions

  • I already found out why the dialog pops up after the "xlApp.Quit()" code. It is for the reason that the program had stated that the xlApp (Excel Application) to quit without saving the changes made in the (.xls) file.

    If it had crossed the path wherein "xlWB_dwg.Save()" executes, then the dialog will then not show.

    Best Regards,

    Jedrick

    Answer Verified By: Jedrick Juinio