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 8716815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:10:37+00:00 2026-06-13T06:10:37+00:00

I have a c# application that is opening a word document, running a .bas

  • 0

I have a c# application that is opening a word document, running a .bas macro, and closing word. All of that works fine. The macro generates 2 message box dialogs with the result of the macro. I want to communicate these messages to my c# application. How can I do this?

Here is my code:

        // Object for missing (or optional) arguments.
        object oMissing = System.Reflection.Missing.Value;

        // Create an instance of Word, make it visible,
        // and open Doc1.doc.
        Word.Application oWord = new Word.Application();
        oWord.Visible = true;
        Word.Documents oDocs = oWord.Documents;
        object oFile = @"c:\\Macro.docm";

        // Open the file.
        Word._Document oDoc = oDocs.Open(ref oFile, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing);

        // Run the macro.
        oWord.GetType().InvokeMember("Run",
        System.Reflection.BindingFlags.Default |
        System.Reflection.BindingFlags.InvokeMethod,
        null, oWord, new Object[] { "MyMacro" });

        // Quit Word and clean up.
        oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
        oDoc = null;
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDocs);
        oDocs = null;
        oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
        oWord = null;

        return "all done!";
  • 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-13T06:10:38+00:00Added an answer on June 13, 2026 at 6:10 am

    The solution I’ve used in the past for this is not for the faint of heart. It basically involves using good old fashioned Windows API calls to find the message box then to enumerate through its “windows” (controls) until you find the control with the text you are after.

    If the message box always has the same title, you should be able to locate the window using the API call FindWindowEx. Once you have its window handle you can use EnumChildWindows to run through its controls until you find the one you are after. You can usually qualify the right control with either GetWindowText or GetClassName or a combination of both. Generally the text of a control should be available with GetWindowText, but I dont know what control MS used for this particular window.

    Good luck!

    FindWindowEx example

    EnumChildWindows example

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

Sidebar

Related Questions

I have a Java application that launches multiple windows (JFrames). It works fine when
I have an VB.Net/C# application that programmatically: Creates an RTF document Open it up
Let me first describe the problem. I have this application that opens a word
I have WPF application. After testing my app on Windows7 and realized that opening
I have a web application that consists of two websites - one running on
I have a GWT application that is giving sporadic 502 errors all of a
We have an application that produces HTML documents which the user opens in word
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in

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.