1

Hi friends i am working on vss 2012, Excel 2013. I am trying to implement the Exporting of Grid view records to the Excel sheet. Excel sheet would be in good style. So what i did is i created a Macro of my design in one excel sheet. So now i have the code of that particular macro.

Now i want to use this macro(Design) in new excel sheets also. Like say every day new records will be added to the grid view, and at the end of the day if i click on export to excel i a new excel should get created with the design of macro, and all records. Is that possible??

What could be the difficulties in implementing this .. I could not find anything related to this in net. So please if anybody know this please let me know...

2
  • It sounds like what you really need is a database... Commented Nov 3, 2014 at 10:38
  • I can normally do Gridview.rendercontrol(HtmltextWriter)..But i need that to be in different template, with some formulas which would fetch the full records details of particular user... Commented Nov 3, 2014 at 10:42

1 Answer 1

2

You can insert VBA macro using this code:

    public void SetVBACode(string _macro)
    {
        VBProject project = workbook.VBProject;
        VBComponents components = project.VBComponents;           
        VBComponent component =components.Add(vbext_ComponentType.vbext_ct_StdModule);
        component.CodeModule.AddFromString(_macro);
    }

And run them using this method:

    public void RunVBACode(string _name)
    {
        excelApplication.RunVBACode(_name);
    }
Sign up to request clarification or add additional context in comments.

4 Comments

please could you clarify input arguemnt of two methods...Is _macro is the path of my macro??
macro - is a test of vba macros as string; _name - is the name of vba macros you want to launch
Is there a possibilty to fetch macro from one xlsm extension workbook, and run that in other worksheet???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.