kcthota

I have word addin with some Forms. When the user performs some operations on these forms, the forms will get a document from the database to temporary location, and open the document in the current active document.

Can I get some sample code/related article to trigger the document open from a form loaded via the addin

Thanks,

Chait




Re: Visual Studio Tools for Office Open document from a form

Cindy Meister

When you say "open the document in the current active document" do you mean to INSERT it into the active Document (so that the content becomes part of the document) Or do you mean to open it as a separate document (increase the number of opened documents)

Which version of Word are you working with, and which programming language are you using

One suggestion I can make without the above information: you want to create a constructor for your Windows Forms class that accepts either the document or the application object your Add-in is working with at the point the form is displayed. This way the code behind the form can work directly with that object.






Re: Visual Studio Tools for Office Open document from a form

kcthota

Hi Cindy,

I have written a method openDoc(String docPath) in ThisAddin.cs which will accept the document path as parameter and open it in the current active document. Now I want to access this method from a form launched from the addin.

I am currently using Word 2007 and C#.

Thanks,

Chait






Re: Visual Studio Tools for Office Open document from a form

kcthota

Hey Cindy,

Thank you very much. Your suggestion has worked!!

The following is the solution.

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

Form1 a = new Form1(this.Application);

a.Show();

}

public partial class Form1 : Form

{

public static Word.Application wordApp = null;

private object missing = Type.Missing;

public Form1(Word.Application wordApp1)

{

wordApp = wordApp1;

InitializeComponent();

}

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void button1_Click(object sender, EventArgs e)

{

object fileName = @"C:\asdf.docx";

wordApp.Application.Documents.Open(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);

}






Re: Visual Studio Tools for Office Open document from a form

Mohan Kumar Karunakaran

Hi,

Can I have the above code in VB.net. I am using Word 2007 & VSTOSE.

Regards,