Click here to Skip to main content
15,889,315 members
Home / Discussions / C#
   

C#

 
Questionstart a form maximized? [modified] Pin
sudany_zool7-Aug-07 17:50
sudany_zool7-Aug-07 17:50 
AnswerRe: start a form maximized? Pin
Christian Graus7-Aug-07 18:16
protectorChristian Graus7-Aug-07 18:16 
QuestionError on ISynchronizeInvoke casting Pin
jacklynn_mei7-Aug-07 16:32
jacklynn_mei7-Aug-07 16:32 
AnswerRe: Error on ISynchronizeInvoke casting Pin
Leslie Sanford7-Aug-07 18:10
Leslie Sanford7-Aug-07 18:10 
GeneralRe: Error on ISynchronizeInvoke casting Pin
jacklynn_mei7-Aug-07 19:45
jacklynn_mei7-Aug-07 19:45 
GeneralRe: Error on ISynchronizeInvoke casting Pin
Leslie Sanford8-Aug-07 4:52
Leslie Sanford8-Aug-07 4:52 
QuestionHelp about Office word In C# Pin
kcynic7-Aug-07 15:31
kcynic7-Aug-07 15:31 
AnswerRe: Help about Office word In C# Pin
tker7-Aug-07 18:16
tker7-Aug-07 18:16 
Hi,

Do you wish to open the Word doc from another process? Do you wish to populate it? Would you like to automate the creation of documents, either before Word opens or by helping the user after it has opened?

Basically to open Word with a new document you need to do the following:

First create a new Windows Forms project. Add a button to the default form.

Next add a reference to the Microsoft Office 12.0 Object Library & Microsoft Word 12.0 Object Library (for Office 2007) so you have access to the word objects. The Office 12.0 Object library is not strictly necessary, but you may find you need it to complete other operations further down the track.

Next use the following as the code behind for Form1:

//START CODE<br />
using System.Windows.Forms;<br />
using Word = Microsoft.Office.Interop.Word;<br />
<br />
namespace WordSample<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        private object m_Missing = Type.Missing;<br />
<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            //create word application<br />
            Word.Application word = new Word.Application();<br />
<br />
            //create word document<br />
            Word.Document wordDoc = new Word.Document();<br />
<br />
            //make visible<br />
            word.Visible = true;<br />
<br />
            //add document to application<br />
            wordDoc.Application.DocumentBeforeSave += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);<br />
            wordDoc = word.Documents.Add(ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing);<br />
<br />
        }<br />
<br />
        void Application_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)<br />
        {<br />
            //PUT YOUR PATH CODE HERE;<br />
        }<br />
<br />
    }<br />
}<br />
<br />
//END CODE<br />


That will create a new instance of word. To modify the closing behaviour there are a number of events available to you including the Application.DocumentBeforeSave or Application.DocumentBeforeClose events. I have included a dummy ApplicationBeforeSave event for you. There is extensive documentation on MSDN regarding the Word ObjectModel that lists all events (http://msdn2.microsoft.com/en-us/library/kw65a0we(vs.80).aspx[^]; http://msdn2.microsoft.com/en-us/library/aa192495(office.11).aspx[^] should get you started, there is also plenty about Office 12/2007 you'll find from there).

If you have any further questions please feel free to ask away. You also have a lot more options for automating word via VSTO with Document or Application level customisations that you may wish to consider.

Hope that helps, good luck and have fun Smile | :)

Toby Russell
Software Engineer
GeneralRe: Help about Office word In C# Pin
kcynic7-Aug-07 19:16
kcynic7-Aug-07 19:16 
GeneralRe: Help about Office word In C# Pin
tker7-Aug-07 20:12
tker7-Aug-07 20:12 
GeneralRe: Help about Office word In C# Pin
kcynic7-Aug-07 21:33
kcynic7-Aug-07 21:33 
GeneralRe: Help about Office word In C# Pin
tker8-Aug-07 16:31
tker8-Aug-07 16:31 
AnswerRe: Help about Office word In C# Pin
MarkB7777-Aug-07 18:53
MarkB7777-Aug-07 18:53 
GeneralRe: Help about Office word In C# Pin
kcynic7-Aug-07 19:18
kcynic7-Aug-07 19:18 
QuestionGetting reflection permissions with ReflectionPermissionAttribute Pin
Luke Murray7-Aug-07 15:23
Luke Murray7-Aug-07 15:23 
QuestionConsole component Pin
noon427-Aug-07 14:31
noon427-Aug-07 14:31 
AnswerRe: Console component Pin
Luc Pattyn7-Aug-07 14:39
sitebuilderLuc Pattyn7-Aug-07 14:39 
GeneralRe: Console component Pin
noon427-Aug-07 14:51
noon427-Aug-07 14:51 
GeneralRe: Console component Pin
Luc Pattyn7-Aug-07 15:04
sitebuilderLuc Pattyn7-Aug-07 15:04 
GeneralRe: Console component Pin
noon427-Aug-07 15:20
noon427-Aug-07 15:20 
QuestionInterface VS Abstract classes Pin
seemamltn7-Aug-07 13:58
seemamltn7-Aug-07 13:58 
GeneralRe: Interface VS Abstract classes Pin
PIEBALDconsult7-Aug-07 14:07
mvePIEBALDconsult7-Aug-07 14:07 
AnswerRe: Interface VS Abstract classes Pin
Christian Graus7-Aug-07 14:30
protectorChristian Graus7-Aug-07 14:30 
AnswerRe: Interface VS Abstract classes Pin
Jeff.Hu7-Aug-07 17:16
Jeff.Hu7-Aug-07 17:16 
AnswerRe: Interface VS Abstract classes Pin
tker7-Aug-07 18:32
tker7-Aug-07 18:32 

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.