none
Porting VBA TO C# RRS feed

  • Question

  • This syntax of VBA generates the type of chart that I need.  How would I do the same in C#?  This is using Microsoft.Office.Interop.Excel & a winform....

        ActiveSheet.Shapes("Chart 9").ScaleWidth 2.1635415573, msoFalse, msoScaleFromBottomRight
        ActiveSheet.Shapes("Chart 9").ScaleHeight 1.8767359288, msoFalse, msoScaleFromBottomRight
        ActiveSheet.Shapes("Chart 9").ScaleWidth 1.4848339701, msoFalse, msoScaleFromTopLeft
        ActiveSheet.Shapes("Chart 9").ScaleHeight 1.3913044829, msoFalse, msoScaleFromTopLeft
        ActiveChart.Axes(xlCategory).Select
        ActiveChart.FullSeriesCollection(2).Select
        ActiveSheet.Shapes("Chart 9").Fill.Visible = msoTrue
        ActiveChart.FullSeriesCollection(2).Select
        Selection.Format.Line.Visible = msoFalse
        With Selection
            .MarkerStyle = 8
            .MarkerSize = 5
        End With
        Selection.MarkerStyle = -4115
        Selection.MarkerSize = 12
        ActiveChart.ChartArea.Select
        ActiveChart.ChartTitle.Select
        Selection.Left = 536.667
        Selection.Top = 6
        ActiveChart.ChartTitle.Text = "A V B"
        Selection.Format.TextFrame2.TextRange.Characters.Text = "A V B"
        With Selection.Format.TextFrame2.TextRange.Characters(1, 33).ParagraphFormat
            .TextDirection = msoTextDirectionLeftToRight
            .Alignment = msoAlignCenter
        End With
        
        'This formats to be the orange lines
        ActiveChart.FullSeriesCollection(2).Select
        ActiveChart.ChartArea.Select
        ActiveChart.FullSeriesCollection(2).ChartType = xlLineMarkers
        ActiveChart.FullSeriesCollection(2).Select
        Selection.Format.Line.Visible = msoFalse
        ActiveChart.ChartArea.Select

    Wednesday, February 8, 2017 2:14 AM

Answers

  • Hi IndigoMontoya,

    Thank you for posting here.

    For your question is more related to Excel, I will move it to Excel for Developers forum for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by IndigoMontoya Thursday, February 9, 2017 1:28 PM
    Thursday, February 9, 2017 5:42 AM

All replies

  • Hi IndigoMontoya,

    Thank you for posting here.

    For your question is more related to Excel, I will move it to Excel for Developers forum for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by IndigoMontoya Thursday, February 9, 2017 1:28 PM
    Thursday, February 9, 2017 5:42 AM
  • Hi,

    If you have no idea to use it in C#, I would suggest you use VB.NET. VB.NET is similar with VBA

          Excel.Worksheet ActiveSheet= xlWorkBook.ActiveSheet;
           
                ActiveSheet.Shapes.Item("Chart 9").ScaleWidth((float)2.1635415573, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromBottomRight);
                ActiveSheet.Shapes.Item("Chart 9").Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                Excel.ChartObjects charts = ActiveSheet.ChartObjects() ;
                Excel.ChartObject chartObject = charts.Add(60, 10, 300, 300);
                Excel.Chart chart = chartObject.Chart;
                Excel.SeriesCollection seriesCollection = chart.FullSeriesCollection(2);
    
                Excel.Series series1 = seriesCollection.Item(1);
                series1.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; ;
                chart.ChartTitle.Text = "A V B";
                chart.ChartTitle.Format.TextFrame2.TextRange.Characters.Text = "A V B";
                chart.ChartTitle.Format.TextFrame2.TextRange.Characters[1, 33].ParagraphFormat.TextDirection = Microsoft.Office.Core.MsoTextDirection.msoTextDirectionLeftToRight;
                chart.ChartTitle.Format.TextFrame2.TextRange.Characters[1, 33].ParagraphFormat.Alignment = Microsoft.Office.Core.MsoParagraphAlignment.msoAlignCenter;

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 10, 2017 9:25 AM
    Moderator