0

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)

6
  • .Documents seems to be Nothing. "The Document object is a member of the Documents collection. The Documents collection contains all the Document objects that are currently open in Microsoft Word.". Are there any documents opened? Additionally _checkLog file and Path params. Commented Dec 30, 2015 at 12:07
  • Hey sir i think that might be a problem. My file and path params are good 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 37 Commented Dec 30, 2015 at 12:21
  • But when i try to convert Excell i got this error Microsoft 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,..... Commented Dec 30, 2015 at 12:22
  • New research i put _log on file before proceed. The function returns True if the file is open. The results :( Log check: 30.12.2015. 13:34:25 File open : False which means file is not opened for sure. Commented Dec 30, 2015 at 12:35
  • Have you tried the first answer of my SO link I posted? Commented Dec 30, 2015 at 12:51

1 Answer 1

1

Open DCOM Config Settings:

1. Start -> dcomcnfg.exe
2. Computer
3. Local Computer
4. Config DCOM
5. Search for Microsoft Word 97-2003 Documents -> Properties

Tab Identity, change from Launching User to Interactive User.

Sign up to request clarification or add additional context in comments.

1 Comment

On the similar way i fixed the excell problem. Thanks sir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.