Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:42:31+00:00 2026-06-06T22:42:31+00:00

I have a website where users generate an Excel report using a macro, when

  • 0

I have a website where users generate an Excel report using a macro, when I try to run it in my local machine it generates perfectly and runs the macro inside Excel. When I publish it into the server and at the same time I am logged in there (RDP open session) and try to run it from a browser outside that server it is also running as expected. The problem occurs when I am logged off in the server (RDP) then run it in a browser outside the server (ie from my machine) the macro does not run but creates my Excel.

This is the code that I am using

public class Report
    {
        protected Workbook Workbook { get; set; }
        protected Application Excel { get; set; }

        public void RunReport()
        {
            // Launch Excel on the server
            Excel = new Application
            {
                DisplayAlerts = false,
                ScreenUpdating = false,
                Visible = false
            };

            // Load the workbook template  
            Workbook = Excel.Workbooks.Open(@"D:\Book1.xlt");

            // Execute macros that generates the report, if any
            ExecuteMacros();

            Workbook.SaveAs(@"D:\Ray'sTesting.xls", XlFileFormat.xlExcel8);
            QuitExcel();

        }
        private void QuitExcel()
        {
            if (Workbook != null)
            {
                Workbook.Close(false);
                Marshal.ReleaseComObject(Workbook);
            }

            if (Excel != null)
            {
                Excel.Quit();
                Marshal.ReleaseComObject(Excel);
            }
        }        
        private void ExecuteMacros()
        {


            const string legacyModuleName = "Module1";
            const string legacyMacroName = "myMacro";

            bool legacyMacroExists = false;
            try
            {
                var legacyMacroModule = Workbook.VBProject.VBComponents.Item(legacyModuleName);
                if (legacyMacroModule != null)
                {
                    int legacyMacroStartLine = legacyMacroModule.CodeModule.ProcStartLine[legacyMacroName, Microsoft.Vbe.Interop.vbext_ProcKind.vbext_pk_Proc];
                    legacyMacroExists = legacyMacroStartLine > 0;
                }
            }
            catch (Exception)
            {
                legacyMacroExists = false;
            }

            if (!legacyMacroExists)
            {
                return;
            }

            // VBA code for the dynamic macro that calls the CI2 legacy macro
            var moduleCode = new StringBuilder();
            moduleCode.AppendLine("Public Sub LaunchLegacyMacro()");
            moduleCode.AppendLine(string.Format("{0}.{1}", legacyModuleName, legacyMacroName));
            moduleCode.AppendLine("End Sub");

            // Add the dynamic macro to the ThisWorkbook module
            var workbookMainModule = Workbook.VBProject.VBComponents.Item("ThisWorkbook");
            workbookMainModule.CodeModule.AddFromString(moduleCode.ToString());

            // Execute the dynamic macro
            Microsoft.VisualBasic.Interaction.CallByName(Workbook, "LaunchLegacyMacro", Microsoft.VisualBasic.CallType.Method, new object[] { });
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:42:34+00:00Added an answer on June 6, 2026 at 10:42 pm

    I got this working by editing the registry every time we run the excel macro by

    private static void ModifyExcelSecuritySettings()
    {
        // Make sure we have programmatic access to the project to run macros
        using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\14.0\Excel\Security", true))
        {
            if (key != null)
            {
                if ((int)key.GetValue("AccessVBOM", 0) != 1)
                {
                    key.SetValue("AccessVBOM", 1);
                }
                key.Close();
            }
        }
    }
    

    So the code should look like this

    public void RunReport()
    {
        ModifyExcelSecuritySettings();
    
        // Launch Excel on the server
        Excel = new Application
        {
            DisplayAlerts = false,
            ScreenUpdating = false,
            Visible = false
        };
    
    .....
    

    I also created a blog post for the full solution which you can view here

    http://anyrest.wordpress.com/2012/06/22/programmatic-execution-excel-macro-on-remote-machine-from-a-website/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have website where users can login with their Facebook account. I am using
I have an ASP.NET website from which the users themselves will generate custom reports
I have a website where users can purchase tickets, but ticket quantities are usually
Say you have a website for users to search for hotel rooms for rent.
I have a website which checks users IP and if its from CA displays
I have a website and right now users can just open a directory and
I have a website created in .NET where users are required to register/login to
I have a website form that collects url of users to store in a
I have a website that prompt the users to enter serial number for a
I have a website for dance academy where Users can register and add/drop dance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.