Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Application using interop Word . . . Code below compiles OK . . but type mismatch error when oDoc.SaveAs.... attempts to execute.

Here are some earlier definitions . . .

Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();

Thanks for any suggestion to fix.

****************

string sFileName = "MYFILE";

object filename = "C:\\JR Temp\\" + sFileName + ".docx";

object Missing = null;

//THE FOLLOWING STATEMENTS PRODUCES TYPE MISMATCH ERROR . . ???

oDoc.SaveAs(ref filename, ref Missing, ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing);
Posted

1 solution

I think there is something with the number of parameters you provided in 'SaveAs' method.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Word;

namespace Test_InteropWord
{
    class Program
    {
        static void Main(string[] args)
        {
            Application app = new Application();


            Document doc = app.Documents.Add(Type.Missing, 
                Type.Missing, 
                WdDocumentType.wdTypeDocument, false);
            doc.SaveAs(@"d:\tmp\test.docx");
            ((Microsoft.Office.Interop.Word._Document)doc).Close(true);
        }
    }
}


SaveAs method:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas%28v=office.14%29.aspx[^]

[update]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// using Microsoft.Office.Interop.Word;
using MyWord = Microsoft.Office.Interop.Word;

namespace Test_InteropWord
{
    class Program
    {
        static void Main(string[] args)
        {
            MyWord.Application app = new MyWord.Application();


            MyWord.Document doc = app.Documents.Add(Type.Missing, 
                Type.Missing,
                MyWord.WdDocumentType.wdTypeDocument, false);
            doc.SaveAs(@"d:\tmp\test.docx");
            ((MyWord._Document)doc).Close(true);
        }
    }
}


When you refer any of classes in that assembly, you can use it with MyWord reference.
 
Share this answer
 
v4
Comments
JOHNNYDEMICHAEL 18-Feb-14 12:38pm    
Debugging . . . showing a lot of compile errors. One is saying SaveAs doesn't have 1 parameter.
Vedat Ozan Oner 18-Feb-14 12:48pm    
have you added reference for Microsoft.Office.Interop.Word?
JOHNNYDEMICHAEL 18-Feb-14 12:50pm    
Yes.
Vedat Ozan Oner 18-Feb-14 12:53pm    
could you put all these compile errors here? I can't say anything without seeing them.
JOHNNYDEMICHAEL 18-Feb-14 12:52pm    
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
using System.Reflection;

using System.Collections;
using System.Globalization;

using System.Threading;
using Office = Microsoft.Office.Core;
using System.Diagnostics;
using Microsoft.VisualBasic.FileIO;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900