Is it possible to create macros in an excel file during runtime and run the same?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pratvik roy
    New Member
    • Sep 2010
    • 3

    #1

    Is it possible to create macros in an excel file during runtime and run the same?

    Hi,

    I am pretty new to VBA.

    I wanted to know if there is a way to create a macro in an excel file and run the same, all in runtime?

    I am using C++ to dump few integer values into an excel sheet and from that i want to create chart automatically.

    Also i need to send the range for chart.

    Regards,
    Pratvik
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. It is possible to do what you ask, but it is more normal to manipulate the Excel sheet directly from VBA by using Excel automation instead of creating macros (i.e. VBA code routines) on the fly within the workbook itself.

    Also, it is simpler to create and format the chart in advance in an Excel workbook with sample data based on a table using the same row sequence and fields as you would expect to export.

    Using the prepared file all you have to do is open the file using VBA code and export the latest data to the table (for example by using the CopyFromRecords et method), then save and close the file. This avoids the need to create the chart in code (which can take a fair bit of effort if the chart requires complex formatting).

    -Stewart

    Comment

    Working...