0

I have a macro (.docm) that opens an rtf file and saves it in .doc format. 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("add file (.docm)");
        OpenFileDialog macroFile = new OpenFileDialog();
        if (macroFile.ShowDialog() != DialogResult.OK)
        {
            MessageBox.Show("Error");
            return;
        }
       
    }

}
lev_
  • 29
  • 3
  • 1
    Does this answer your question? [How-to: Run existing Word VBA Macros from C# Ribbon Addin](https://stackoverflow.com/questions/1735815/how-to-run-existing-word-vba-macros-from-c-sharp-ribbon-addin) – braX Jan 26 '22 at 10:07

1 Answers1

0

After you have got a file name you can use the Documents.Open method which opens the specified document and adds it to the Documents collection. The Document.SaveAs2 method allows saving the specified document with a new name or format. Some of the arguments for this method correspond to the options in the Save As dialog box (File tab). The format in which the document is saved. Can be any WdSaveFormat constant. It seems you are interested in the wdFormatDocument value.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45