Click here to Skip to main content
15,903,203 members
Home / Discussions / C#
   

C#

 
AnswerRe: collections Pin
Alan Balkany9-Sep-08 7:56
Alan Balkany9-Sep-08 7:56 
GeneralRe: collections Pin
bhatted9-Sep-08 8:14
bhatted9-Sep-08 8:14 
QuestionDatabase Update Error Pin
MumbleB9-Sep-08 6:02
MumbleB9-Sep-08 6:02 
AnswerRe: Database Update Error Pin
Guffa9-Sep-08 6:04
Guffa9-Sep-08 6:04 
GeneralRe: Database Update Error Pin
MumbleB9-Sep-08 6:10
MumbleB9-Sep-08 6:10 
GeneralRe: Database Update Error Pin
Guffa9-Sep-08 10:38
Guffa9-Sep-08 10:38 
GeneralRe: Database Update Error Pin
MumbleB9-Sep-08 6:19
MumbleB9-Sep-08 6:19 
QuestionWOrd Automation Pin
burrows.stephen9-Sep-08 5:41
burrows.stephen9-Sep-08 5:41 
Hi I'm writing an app that will have some Word automation, but I can not be certain if the user has already got an instance of word open, if they do i wish to use there unstance do my automation or else start a new instance. My problem is if they have it open my code makes a new instance and will close down the both instance when i finish can any one help.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Word=Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
using core= Microsoft.Office.Core;
using System.Diagnostics;
namespace WordProcess
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		
		Word.Application wordApp;
		Word._Document wordDocument;
		

		object document;
		object wordFalse = false;
		object wordTrue = true;
		object dynamic = 2;
		
		object wordMissing = System.Reflection.Missing.Value;
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			
			System.Diagnostics.Process[] wordPro = System.Diagnostics.Process.GetProcessesByName("winword");
			if (wordPro.Length==0){
				//No word Open start a new word process.
				Process p= Process.Start("WINWORD.EXE");
				p.WaitForInputIdle();
				
				
			}
			try{
				object filePath =@"C:\test.doc";
				object filePath1 =@"C:\test1.doc";
				wordDocument = new Word.DocumentClass();
				
				
				wordApp = (Word.Application)Marshal.GetActiveObject("Word.Application");
				
				
				wordApp.Documents.Open(ref filePath, ref wordMissing, ref wordFalse, ref wordMissing,
				                       ref wordMissing, ref wordMissing, ref wordMissing, ref wordMissing,
				                       ref wordMissing, ref wordMissing, ref wordMissing, ref wordTrue,
				                       ref wordMissing, ref wordMissing, ref wordMissing, ref wordMissing);
				
				
				
				wordDocument.SaveAs(ref filePath1, ref wordMissing, ref wordFalse, ref wordMissing,
				                    ref wordMissing, ref wordMissing, ref wordMissing, ref wordMissing,
				                    ref wordMissing, ref wordMissing, ref wordMissing, ref wordTrue,
				                    ref wordMissing, ref wordMissing, ref wordMissing, ref wordMissing);
				
				wordDocument.Close(ref wordFalse, ref wordMissing, ref wordMissing);//Close the document no saving


				wordApp.Quit(ref wordMissing, ref wordMissing, ref wordMissing);//Remove the instance opened
				
				
			}catch(MarshalDirectiveException mw){
				MessageBox.Show(mw.ToString());
			}catch(Exception ex){
				MessageBox.Show(ex.ToString());
			}
			
			
		}
		
		
		
	}

}

AnswerRe: WOrd Automation Pin
dan!sh 9-Sep-08 5:51
professional dan!sh 9-Sep-08 5:51 
GeneralRe: WOrd Automation Pin
burrows.stephen9-Sep-08 5:56
burrows.stephen9-Sep-08 5:56 
GeneralRe: WOrd Automation Pin
dan!sh 9-Sep-08 6:06
professional dan!sh 9-Sep-08 6:06 
GeneralRe: WOrd Automation Pin
burrows.stephen9-Sep-08 6:27
burrows.stephen9-Sep-08 6:27 
GeneralRe: WOrd Automation Pin
Dan Neely9-Sep-08 6:57
Dan Neely9-Sep-08 6:57 
GeneralRe: WOrd Automation Pin
dan!sh 9-Sep-08 9:05
professional dan!sh 9-Sep-08 9:05 
GeneralRe: WOrd Automation Pin
Dan Neely9-Sep-08 9:50
Dan Neely9-Sep-08 9:50 
GeneralRe: WOrd Automation Pin
vikas amin9-Sep-08 7:47
vikas amin9-Sep-08 7:47 
Questionhow can i draw a rectangle from a separate antoher winForm? Pin
maifs9-Sep-08 5:23
maifs9-Sep-08 5:23 
AnswerRe: how can i draw a rectangle from a separate antoher winForm? Pin
zafersavas9-Sep-08 5:49
zafersavas9-Sep-08 5:49 
AnswerRe: how can i draw a rectangle from a separate antoher winForm? Pin
DaveyM699-Sep-08 6:59
professionalDaveyM699-Sep-08 6:59 
QuestionValidating event in a Dialog form Pin
Gareth H9-Sep-08 5:21
Gareth H9-Sep-08 5:21 
AnswerRe: Validating event in a Dialog form Pin
Wendelius9-Sep-08 7:25
mentorWendelius9-Sep-08 7:25 
GeneralRe: Validating event in a Dialog form Pin
Gareth H9-Sep-08 22:28
Gareth H9-Sep-08 22:28 
GeneralRe: Validating event in a Dialog form Pin
Wendelius10-Sep-08 8:02
mentorWendelius10-Sep-08 8:02 
Question[Message Deleted] Pin
Yathish hatter9-Sep-08 4:29
Yathish hatter9-Sep-08 4:29 
AnswerRe: please Help me C# Pin
Anthony Mushrow9-Sep-08 4:33
professionalAnthony Mushrow9-Sep-08 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.