Automate Your Charts

You can automate your Mekko Graphics charts using VBA or C#.

VBA Automation

/// Return true if shape is a MekkoGraphics chart

bool IsMekkoChart(PowerPoint.Shape sh);

/// This function will open the provided Mekko Graphics chart for editing

void EditMekkoChart(PowerPoint.Shape sh);

/// This function will save and close the currently opened Mekko Graphics chart

void SaveAndCloseMekkoChart();

/// This function returns True if the provided Shape is a Mekko Graphics chart

bool IsMekkoChart(PowerPoint.Shape sh);

/// This function will extract the chart data from the currently opened Mekko Graphics chart

string[,] GetOpenedChartData();

/// This function will extract the chart data from the provided Mekko Graphics chart

string[,] GetChartData(PowerPoint.Shape shape);

/// This function will inject the chart data into the currently opened Mekko Graphics chart

void SetOpenedChartData(string [,] data);

/// This function will inject the chart data into the provided Mekko Graphics chart

PowerPoint.Shape SetChartData(PowerPoint.Shape shape, string[,] data);

/// This function will refresh the Excel Link (if any) for the provided Mekko Graphics chart

bool RefreshExcelLink(PowerPoint.Shape shape);

/// This function will Update the provided Mekko Graphics chart

bool RefreshChart(PowerPoint.Shape shape);

/// Replaces entire ChartDataArray

void ReplaceOpenedChartDataArray(string[,] data);

/// Replaces entire ChartDataArray for shape

PowerPoint.Shape ReplaceChartDataArray(PowerPoint.Shape shape, string[,] data);

VBA Sample Code

Switch to Microsoft Visual Basic Editor (Alt+F11) to see more code samples

// VBA

 

Sub UpdateSelectedChart()

    Dim addIn As COMAddIn

    Dim MG_utilities As Object

   

    Dim sel As Selection

    Dim sh As Shape

   

    Set addIn = Application.COMAddIns(“MekkoGraphicsAddin“)

    Set MG_utilities = addIn.Object

   

    If (MG_utilities Is Not Null) Then

        Set sel = ActiveWindow.Selection

        If (sel.ShapeRange.Count = 1) Then

            Set sh = sel.ShapeRange(1)

            If (MG_utilities.IsMekkoChart(sh)) Then

                MG_utilities.RefreshChart (sh)

            End If

        End If

    End If

End Sub

C# Automation

public interface IAddInUtilities

{

void EditMekkoChart(PowerPoint.Shape sh);

void OpenTaskPanes(PowerPoint.Shape sh);

void SaveAndCloseMekkoChart();

bool IsMekkoChart(PowerPoint.Shape sh);

string[,] GetOpenedChartData();

string[,] GetChartData(PowerPoint.Shape shape);

///

/// Only Replaces corresponding cell values in ChartDataArray if cells and valueas are not empry. Does not change size of ChartDataArray

///

void SetOpenedChartData(string[,] data);

///

/// Only Replaces corresponding cell values in ChartDataArray if cells and valueas are not empry. Does not change size of ChartDataArray

///

PowerPoint.Shape SetChartData(PowerPoint.Shape shape, string[,] data);

///

/// Replaces entire ChartDataArray

///

///

///

///

void ReplaceOpenedChartDataArray(string[,] data);

///

/// Replaces entire ChartDataArray

///

///

///

///

PowerPoint.Shape ReplaceChartDataArray(PowerPoint.Shape shape, string[,] data);

bool RefreshExcelLink(PowerPoint.Shape shape);

bool RefreshChart(PowerPoint.Shape shape);

bool ConvertChart(PowerPoint.Shape shape);

}

C# Sample Code

// C#

 

// First set a reference to MekkoAddin10.dll located in the Mekko Graphics installation folder

public void UpdateSelectedChart(Office.IRibbonControl control)

{

  object addInName = “MekkoGraphicsAddin“;

  Office.COMAddIn addIn = Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName);

  WizardAddin.IAddInUtilities MG_utilities = (WizardAddin.IAddInUtilities)addIn.Object;

 

  if (MG_utilities != null)

  {

  PowerPoint.DocumentWindow dw = Globals.ThisAddIn.Application.ActiveWindow;

  PowerPoint.Selection sel = dw.Selection;

  if (sel.ShapeRange.Count == 1)

  {

  PowerPoint.Shape sh = sel.ShapeRange[1];

  if (MG_utilities.IsMekkoChart(sh))

  MG_utilities.RefreshChart(sh);

  }

  } 

}

 

 

Download Automating Your Charts presentation.