public static void Run()
        {
            // ExStart:AddVBAModuleOrCode
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create new workbook
            Workbook workbook = new Workbook();

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Add VBA Module
            int idx = workbook.VbaProject.Modules.Add(worksheet);

            // Access the VBA Module, set its name and codes
            Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[idx];
            module.Name = "TestModule";

            module.Codes = "Sub ShowMessage()" + "\r\n" +
                           "    MsgBox \"Welcome to Aspose!\"" + "\r\n" +
                           "End Sub";

            // Save the workbook
            workbook.Save(dataDir + "output_out_.xlsm", SaveFormat.Xlsm);
            // ExEnd:AddVBAModuleOrCode
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            Aspose.Cells.Workbook  workbook = new Aspose.Cells.Workbook();
            Aspose.Cells.Worksheet sheet    = workbook.Worksheets[0];

            int moduleIdx = workbook.VbaProject.Modules.Add(sheet);

            Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[moduleIdx];
            module.Codes =
                "Sub ShowMessage()" + "\r\n" +
                "    MsgBox \"Welcome to Aspose!\"" + "\r\n" +
                "End Sub";

            Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);
            button.Placement   = Aspose.Cells.Drawing.PlacementType.FreeFloating;
            button.Font.Name   = "Tahoma";
            button.Font.IsBold = true;
            button.Font.Color  = System.Drawing.Color.Blue;
            button.Text        = "Aspose";

            button.MacroName = sheet.Name + ".ShowMessage";

            workbook.Save(outputDir + "outputAssignMacroToFormControl.xlsm");

            Console.WriteLine("AssignMacroToFormControl executed successfully.");
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            if (!System.IO.Directory.Exists(dataDir))
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            Aspose.Cells.Workbook  workbook = new Aspose.Cells.Workbook();
            Aspose.Cells.Worksheet sheet    = workbook.Worksheets[0];

            int moduleIdx = workbook.VbaProject.Modules.Add(sheet);

            Aspose.Cells.Vba.VbaModule module = workbook.VbaProject.Modules[moduleIdx];
            module.Codes =
                "Sub ShowMessage()" + "\r\n" +
                "    MsgBox \"Welcome to Aspose!\"" + "\r\n" +
                "End Sub";

            Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);
            button.Placement   = Aspose.Cells.Drawing.PlacementType.FreeFloating;
            button.Font.Name   = "Tahoma";
            button.Font.IsBold = true;
            button.Font.Color  = System.Drawing.Color.Blue;
            button.Text        = "Aspose";

            button.MacroName = sheet.Name + ".ShowMessage";

            workbook.Save(dataDir + "Output.out.xlsm");

            Console.WriteLine("File saved");
            //ExEnd:1
        }