L
L
lev892022-01-26 12:57:34
Visual Basic
lev89, 2022-01-26 12:57:34

How to run a macro from C#?

I have a macro (.docm) that opens an rtf file and saves it as a doc. This macro needs to be run from a C# application. How to do it?

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
            // Создание экземпляра Word
            Word.Application app = new Word.Application();
            app.Visible = true;
 
            Word.Documents doc = app.Documents;
 
            // Открытие файлов
            MessageBox.Show("Добавьте файл с макросом");
            OpenFileDialog macroFile = new OpenFileDialog();
            if (macroFile.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Ошибка открытия макроса");
                return;
            }
           
        }
 
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-01-26
@freeExec

https://docs.microsoft.com/en-us/office/vba/api/wo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question