2
Answers

Create Word Document in vb.net

Ask a question
Hi,
I need to create a new ms word document with my desired given name using vb.net.
For that i have written a simple code as below

Dim wordApp As Microsoft.Office.Interop.Word.Application
Dim wordDoc As Microsoft.Office.Interop.Word.

wordApp = New Microsoft.Office.Interop.Word.Application
wordDoc = wordApp.Documents.Add
wordApp.Visible = True

This code runs perfectly, but i want to create a new document with my given name.
I want to give it name as "Order No. 1" 
where the text "Order No." will be static and the number will be fetched from database and added +1
for that i have tried 

Dim wordName as Object "Order No."
wordDoc = wordApp.Documents.Add(wordName)

but this line gives error.

COMException was unhandled
Word was unable to read this document. It may be currupt.
Try one or more of the following:
* Open and Repair the file.

Whats the error in my code, please inform me.
More i want to ask you is that i have searched in google 
where every one use Word.Application, but i have to use Microsoft.Office.Interop.Word.Application
where i have imported Microsoft.Office.Interop.Word.


Give Proper Solution.
Thanks

Answers (2)