S
sclarke18
Hi,
I have a class that automatically creates a reference for Open Word
application, and then proceeds to save all the open versions. However,
sometimes it displays the "save as" dialog box, which I want to avoid as
there won't be a user there to hit yes. I was thinking about something like
'Application.DisplayAlerts = false', but this doesn't work as below.
Also another more minor point is that when I call the close, it shows a
warning showing 'Ambiguity between method
'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref
object)' and non-method 'Microsoft.Office.Interop.Word.' - any ideas on how
to specify this properly so as to remove this warning.
Here is my code so far:
using System;
using System.Collections;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using Microsoft.Office;
using System.Reflection;
using System.Diagnostics;
using System.Security.AccessControl;
using Word = Microsoft.Office.Interop.Word;
namespace docs
{
class WDoc
{
public static void WClass()
{
Object oMissing = System.Reflection.Missing.Value;
//Get reference to application
Word._Application oWordApp = (Word._Application)System.Runtime
..InteropServices.Marshal.GetActiveObject("Word.Application");
//Save each open Word document with its original name
foreach (Word.Document document in oWordApp.Documents)
{
Object oSaveAsFileWord = document.Name;
//Save active files
oWordApp.ActiveDocument.SaveAs(ref oSaveAsFileWord,
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);
//oWordApp.Application.DisplayAlerts = false; ????
//Don't save any more changes
object DoNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
oWordApp.ActiveDocument.Close(ref DoNotSaveChanges, ref oMissing, ref
oMissing);
}
//Quit Word
oWordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
return;
}}}
I have a class that automatically creates a reference for Open Word
application, and then proceeds to save all the open versions. However,
sometimes it displays the "save as" dialog box, which I want to avoid as
there won't be a user there to hit yes. I was thinking about something like
'Application.DisplayAlerts = false', but this doesn't work as below.
Also another more minor point is that when I call the close, it shows a
warning showing 'Ambiguity between method
'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref
object)' and non-method 'Microsoft.Office.Interop.Word.' - any ideas on how
to specify this properly so as to remove this warning.
Here is my code so far:
using System;
using System.Collections;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using Microsoft.Office;
using System.Reflection;
using System.Diagnostics;
using System.Security.AccessControl;
using Word = Microsoft.Office.Interop.Word;
namespace docs
{
class WDoc
{
public static void WClass()
{
Object oMissing = System.Reflection.Missing.Value;
//Get reference to application
Word._Application oWordApp = (Word._Application)System.Runtime
..InteropServices.Marshal.GetActiveObject("Word.Application");
//Save each open Word document with its original name
foreach (Word.Document document in oWordApp.Documents)
{
Object oSaveAsFileWord = document.Name;
//Save active files
oWordApp.ActiveDocument.SaveAs(ref oSaveAsFileWord,
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);
//oWordApp.Application.DisplayAlerts = false; ????
//Don't save any more changes
object DoNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
oWordApp.ActiveDocument.Close(ref DoNotSaveChanges, ref oMissing, ref
oMissing);
}
//Quit Word
oWordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
return;
}}}