473,612 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'Type Mismatch' exception when calling Word.Applicatio n.Documents.Ope n method in Office (Word) 2003 PIA from C#

Hi,

I'm getting a 'Type mismatch' exception when calling the
Word.Applicatio n.Documents.Ope n method when using the Office XP 2003
PIAs. the actual error is:

System.Runtime. InteropServices .COMException (0x80020005): Type
mismatch.

This method works when using the Office XP PIAs (not that this fact is
much to go by) but sadly:

1) the number of arguments changes between versions of the PIA
2) this error occurs

Has anyone had a similar problem? My code couldn't be simpler (minus
exception handling):

private static Word.Document openDocument(Wo rd.Application application,
string sFileName)
{
Word.Document dDocument = null;

object oReadOnly = true;
object oIsVisible = false;
object oMissing = System.Reflecti on.Missing.Valu e;

dDocument = application.Doc uments.Open(
ref sFileName,
ref oMissing,
ref oReadOnly,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oIsVisible,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);

return dDocument;
}

Can anyone help?! Alternatives/workarounds/hair replacement therapy all
welcome...

Cheers,
Rich

Nov 17 '05 #1
1 11549
Ron
try:

Microsoft.Offic e.Interop.Word. ApplicationClas s app = new
Microsoft.Offic e.Interop.Word. ApplicationClas s();

"we******@urban perspective.net " wrote:
Hi,

I'm getting a 'Type mismatch' exception when calling the
Word.Applicatio n.Documents.Ope n method when using the Office XP 2003
PIAs. the actual error is:

System.Runtime. InteropServices .COMException (0x80020005): Type
mismatch.

This method works when using the Office XP PIAs (not that this fact is
much to go by) but sadly:

1) the number of arguments changes between versions of the PIA
2) this error occurs

Has anyone had a similar problem? My code couldn't be simpler (minus
exception handling):

private static Word.Document openDocument(Wo rd.Application application,
string sFileName)
{
Word.Document dDocument = null;

object oReadOnly = true;
object oIsVisible = false;
object oMissing = System.Reflecti on.Missing.Valu e;

dDocument = application.Doc uments.Open(
ref sFileName,
ref oMissing,
ref oReadOnly,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oIsVisible,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);

return dDocument;
}

Can anyone help?! Alternatives/workarounds/hair replacement therapy all
welcome...

Cheers,
Rich

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2877
by: nmueggler | last post by:
Hi I'm working on a Word 2003 mail merge component for a windows client. My problem is that the BeforePrint Event ist not raised if the user is printing directly out of word, but if I'm running the PrintOut command in the code it is working! I'm using Office 2003 with the appropriate PIA's. The code looks like this:
7
6235
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does what I need it to do. But it has two problems: (1) it runs very slowly, and (2) it does not seem to...
3
30773
by: Adam Faulkner via DotNetMonster.com | last post by:
I want to create a method within a class that opens a Microsoft Word 2000 Document and has the facility to Create a new word document and then extract a Page that exists within the original Word Document and save it to a new Word Document. I would need to generate a loop for each page found within a word document to create a new word document and insert the existing page into the new word document and then save as a new word document. ...
4
2025
by: enak | last post by:
I need to open a Word template so that I can merge some data from a database with the document. I am using ASP.NET, VB.NET. I can not even get MS Word to be visible. I can see that an instance is created in Task Manager. Here is my code: Private Sub createReport() Dim missing As Object = System.Reflection.Missing.Value Dim file_name As String Dim file_path As String
4
5112
by: herman404 | last post by:
Hi everyone, I am trying to write a function that will be called from another function. It will do a save as on a word document, and the document name will be passed via a parameter. I keep getting a Type Mismatch error on the Documents.Open call below, but it works fine when I specify the name of the file in the Open call. How come it doesn't work with the parameter, even when I declare a local variable and set it equal to the...
5
2991
by: Bob | last post by:
I'm getting error 8007007e when executing the following code. Dim word As New Microsoft.Office.Interop.Word.Application Dim doc As Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(WordFileName.ToString) doc.Activate() word.Visible = True This code works on the development machine, but does not work on a test machine. The test machine is set up to use Office 2003, same as the development one.
1
18907
by: tamasumalta | last post by:
I am using the attached code Private Sub StartApplicationProcess InitialiseObject() oWord.Visible = True oDoc = oWord.Documents.Open(StrStackPath) oWord.Visible = True end sub The variables oWord and oDoc are declared in the class as below
1
4377
by: dittytwo | last post by:
Hi there The below code works if you don't try to do anything to the word document which is great (Not :D) I am having problems with the context command both text (i.e initial document with no text) or a subsequent addition of text, insert, to the document. as this is going to be used along side other com opened applications Excel power point etc. it needs to work in the self.X orientation as i can get it to work normally see code 2 ...
1
12172
by: gokulraj84 | last post by:
This is my Coding. Application newApp = new Application(); // Response. // specifying the Source & Target file names // c:\\abc\\Source.doc; object Source = "F:\\Gokulraj\\doc2.doc"; object Target = "F:\\Gokulraj\\Temp\\gokul.pdf";
0
8173
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8254
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6082
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4111
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1416
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.