Click here to Skip to main content
15,919,931 members
Home / Discussions / C#
   

C#

 
AnswerRe: Export datagrid to excel Pin
Manas Bhardwaj9-Sep-08 10:24
professionalManas Bhardwaj9-Sep-08 10:24 
AnswerRe: Export datagrid to excel Pin
Trushal1921-Sep-13 4:35
Trushal1921-Sep-13 4:35 
QuestionCrystal Report Help.. Pin
Slick699-Sep-08 10:01
Slick699-Sep-08 10:01 
Questionsplitter style Pin
Jassim Rahma9-Sep-08 9:24
Jassim Rahma9-Sep-08 9:24 
AnswerRe: splitter style Pin
Wendelius9-Sep-08 11:39
mentorWendelius9-Sep-08 11:39 
QuestionHowTo: Start a msi File in an Installation Pin
Ariadne9-Sep-08 9:19
Ariadne9-Sep-08 9:19 
AnswerRe: HowTo: Start a msi File in an Installation Pin
Manas Bhardwaj9-Sep-08 10:26
professionalManas Bhardwaj9-Sep-08 10:26 
GeneralRe: HowTo: Start a msi File in an Installation Pin
Ariadne9-Sep-08 10:58
Ariadne9-Sep-08 10:58 
Question[Message Deleted] Pin
bhatted9-Sep-08 7:53
bhatted9-Sep-08 7:53 
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 

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.