I am trying to create a Word document from Ms Visual Basic 2010 by means of a button on a form, I have already added the reference of Microsoft Word 15.0 Object Library
to the project, the Word document is created successfully and saves it, but after doing that shows me the following error.
I attach my code:
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub btncrear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncrear.Click
'Declara la variable.
Dim objWD As Word.Application
'Crea una nueva instancia de Word
objWD = CreateObject("Word.Application")
'Agrega un nuevo documento en blanco
objWD.Documents.Add()
'Agrega Texto.
objWD.Selection.TypeText("Hola mundo")
'Guarda el documento
objWD.ActiveDocument.SaveAs(FileName:="cotizacion.doc")
objWD = objWD.Documents.Open(FileName:="cotizacion.doc")
End Sub
End Class