Re: Visual Studio to Word
Hey Beast,
You can do this with Visual Studio Tools for Office.
Hope this helps.
Re: Visual Studio to Word
Or check out my Office FAQ (link in my signature).
Re: Visual Studio to Word
I had the following code working for opening a word document. However, I tried adding in Office XP PIA's and since then it has not worked. I uninstalled all the PIA's and still not working. I get this error:
Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
nmadd - The clients machines are all XP - will those Visual Studio Tools for Office work with XP, it looks like they are for 2003.
Here is the code that was working:
Code:
private void button6_Click(object sender, EventArgs e)
{
object fileName = "M:\\Public\\SOPs\\CFSCE SOPS\\English\\300 - Training Support\\302_Annex H.doc";
object readOnly = false;
Word.ApplicationClass WordApp = new Word.ApplicationClass();
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
aDoc.Activate();
}
Re: Visual Studio to Word
I just tried my solution on a second machine loaded with VS2005 and it still works on it. So, I am guessing trying to get those PIA"s to work has buggered up my VS. Is there a way to reload the Word references in VS, not my solution, I have tried that.
Re: Visual Studio to Word
You should be using Word.Application and not he Word.ApplicationClass.
How are you deploying your app? You will need the PIAs for whatever version of Office you are using/supporting if using the .Interop class. Otherwise completely using Late Binding and Reflection is what you will have to use.
Re: Visual Studio to Word
please explain both of those terms or link to a doc you have explained them in? I am pretty good at coding inside word/access/excel but i suck at controlling them from vb
Re: Visual Studio to Word
Re: Visual Studio to Word
Late Binding and Reflection
Re: Visual Studio to Word
The only reason I started down this PIA road was because I checked MS and then had examples but you needed to install PIA's. I am guessing I just went down a wrong road. Obviously, I need to play with some of your links first.
I changed the statement to:
Code:
Word.Application WordApp = new Word.Application();
and still get this error:
Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
Re: Visual Studio to Word
I just looked through your link, and for Word, it looks like most of the examples are for VB6. I am currently trying to work in C# VS2005 but I know VB 2003 better. Do you have an example to open a word doc in C# VS2003 or VS2005.
Re: Visual Studio to Word
I had a look at the Visual Studio Tools for Office and it is for Office 2003. We are going to migrate there in 6 weeks but this project cannot wait that long.
Re: Visual Studio to Word
Late Binding and Reflection to Automate an Office app in C#:
http://vbforums.com/showpost.php?p=2580243&postcount=2
Re: Visual Studio to Word
Not sure how relevant this is in the current discussion but there are different PIA for the different versions of the installed office. Try to find those that are for the version you have on your machines.
Re: Visual Studio to Word
Yes, there are only PIAs for 2002, 2003 and 2007. If you have a previous version of Office then you need to use Late Binding. Also, you need to create separate setups for each version you are supporting when using PIAs.
Link in my signature ;)