Exception thrown every time in console application while running this simple code
Public Function convertWord(ByVal file As String, ByVal Path As String) As Integer
Dim convertObj As Microsoft.Office.Interop.Word.Application
Dim WordDoc As Microsoft.Office.Interop.Word.Document
Try
convertObj = New Microsoft.Office.Interop.Word.Application
WordDoc = New Microsoft.Office.Interop.Word.Document
WordDoc = convertObj.Documents.Open(Path)
WordDoc.ExportAsFixedFormat(file, WdExportFormat.wdExportFormatPDF)
Return 2
Catch ex As Exception
_checkLog("Originalna greška je : " & ex.Message & ex.StackTrace)
Return 5
End Try
End Function
If i use debug mode this function works perfect. Otherwise
Log check: 30.12.2015. 11:17:15 Originalna greška je : Object reference not set to an instance of an object. Line 34
Line 34>>>WordDoc = convertObj.Documents.Open(Path)
_checkLogfileandPathparams.Log check: 30.12.2015. 13:19:12 File je : G:\POSLOVNO\menzur\635870783515338248.pdf Log check: 30.12.2015. 13:19:12 Path je : G:\POSLOVNO\menzur\635870783515338248.docx Log check: 30.12.2015. 13:19:13 Originalna greška je : Object reference not set to an instance of an object. at OfficeConvert.convertWord(String file, String Path) in C:\Users\Desktop\servis\OfficeConvert.vb:line 37Microsoft Excel cannot access the file '...0680735.xlsx'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter,.....Log check: 30.12.2015. 13:34:25 File open : Falsewhich means file is not opened for sure.