471,337 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Document.Open Office Example

Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activate();
wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian
Jan 16 '06 #1
4 18435
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #2
Fabian,
you need to ensure the document actually exists at the path specified, and
that you have all upper and lower casing exact.
For example, this path:

object path = "C:\\temp\\Test.doc";

would open "Test.doc" from the C:\temp folder.
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Fabian" wrote:
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activate();
wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #3
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #4
Sorry, I forgot to say :

I use
VS2005.NET C#
Office2003
Windows2000


"Fabian" wrote:
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Emily John | last post: by
8 posts views Thread by Asma | last post: by
1 post views Thread by Marco Moioli | last post: by
4 posts views Thread by Jon Westmore | last post: by

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.