Rajarajan

Rajarajan

  • NA
  • 14
  • 11.8k

adding content Word application not working in vb.net

Jun 25 2015 10:23 AM
I am using below code in asp.net vb.net to create an object for word document to write in it. But receiving the below error. please help me in fixing this. I already used this code in another machine it worked perfectly. But i used this code in new machine where software newly installed. it is not working in the new machine.
 
Error:
 Object variable or With block variable not set
 This command is not available because no document is open
 
 
Code:
Dim fso As Object
Dim doc As Object
Dim objWord As Object
Dim WordDocument As Object
fso = CreateObject("Scripting.FileSystemObject")
objWord = CreateObject("word.application")
WordDocument = objWord.documents
doc = WordDocument.open(DestFileName)
With objWord.Selection.Find
.
.
.
End With
objWord.ActiveDocument.Save()
objWord.ActiveDocument.Close()
objWord.Quit()
fso = Nothing
doc = Nothing