none
How can i achieved Excel record macro function in VSTO? RRS feed

  • Question

  • hello

        I want to know user all  Action like  record macro that

    like  make Range backColor to red

    add a shape

    Range sort  

    i want to extend event like this    

    NewShape(sh as shape)

    so i can use the event to know about new shape info.

    newStyle(target as range)

    i can use this event to know a range have new style.i can do something 

    that's all

    thanks.


    Friday, February 23, 2018 3:30 PM

All replies

  • Hello hu_1990,

    It seems that you want to convert a recorded VBA macro that records your actions to VSTO. 

    What's the code of the recorded VBA macro? What action did you you? Is your VSTO project developed in C#/VB.Net?

    Best Regards,

    Terry


    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.

    Monday, February 26, 2018 5:06 AM

  • my english not good. sorry about that

    i want know user all actions in excel.

    when i click the  record macro button , i get this

    ActiveCell.FormulaR1C1 = "1"
        Range("C7").Select
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, 177.75, 31.5, 142.5, 48.75).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "hee"
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 3).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            .Fill.ForeColor.Brightness = 0
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With

    so how can i get this code in vsto but not use the record macro function.


    i want save user actions to dataBase

    I use the C#  thank you



    • Edited by hu_1990 Tuesday, February 27, 2018 6:34 AM
    Tuesday, February 27, 2018 6:33 AM
  • my english not good. sorry about that

    i want know user all actions in excel.

    when i click the  record macro button , i get this

    ActiveCell.FormulaR1C1 = "1"
        Range("C7").Select
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, 177.75, 31.5, 142.5, 48.75).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "hee"
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 3).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            .Fill.ForeColor.Brightness = 0
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With

    so how can i get this code in vsto but not use the record macro function.

    i want save user actions to dataBase

    I use the C#  thank you

    Tuesday, February 27, 2018 6:35 AM
  • Hello hu_1990,

    What's the result you want to get? I tried to hard code to convert the macro to VSTO and I would suggest you check if it could work for you.

    Excel.Application application = Globals.ThisAddIn.Application;
                application.ActiveCell.FormulaR1C1 = "1";
                Excel.Worksheet worksheet = application.ActiveSheet;
                worksheet.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,
                    (float)177.75, (float)31.5, (float)142.5, (float)48.75).Select();
                application.Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "hee";
                var font = application.Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 3).Font;
                font.NameComplexScript = "+mn-cs";
                font.NameFarEast = "+mn-ea";
                font.Fill.Visible = true;
                font.Fill.ForeColor.ObjectThemeColor = Office.MsoThemeColorIndex.msoThemeColorLight1;
                font.Fill.ForeColor.TintAndShade = 0;
                font.Fill.ForeColor.Brightness = 0;
                font.Fill.Transparency = 0;
                font.Fill.Solid();
                font.Size = 11;
                font.Name = "+mn-lt";

    Remember using:

    using Office=Microsoft.Office.Core;
    using Excel = Microsoft.Office.Interop.Excel;

    Best Regards,

    Terry


    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.

    Wednesday, February 28, 2018 9:05 AM