Question Status

Verified
NYNavDev asked a question on 14 Feb 2018 10:05 AM

We are trying to create an outlook appointment from a NAV Contact card with a hyperlink in the appointment body, back to the Contact card. Everything is working except for the hyperlink. When we try to set the Selection from Word.window.selection, we get this error: A call to Microsoft.Office.Interop.Word.Window.Selection failed with this message: Object does not match target type. We are using WordSelection dotnet variable set to Word.Selection object. We have this working in Visual Studio 2017, but cannot get past this error in NAV 2015. We are using Word to add the hyperlink to outlook appointment.

Reply
Suggested Answer
Stefano Demiliani responded on 14 Feb 2018 2:49 PM

It seems a cast error. Are you sure that the selected element is exactly what you want? Is Word.selection the correct object you're casting?

Reply
NYNavDev responded on 14 Feb 2018 3:20 PM

I am as sure as I can be. I set the same variables in VB 2017 and it worked.

This is the line throwing the error:

WordSelection := WordWindow.Selection();

WordSelection defined as Interop.Word.Selection

WordWindow defined as Interop.Word.Window

Reply
Suggested Answer
Stefano Demiliani responded on 14 Feb 2018 3:42 PM

Strange... this seems a cast error or an object non initialized error.

Reply
Suggested Answer
Suresh Kulla responded on 14 Feb 2018 7:17 PM

In Standard NAV check the codeunit 5054 and see if there is anything helpful to achieve it.

Reply
Verified Answer
NYNavDev responded on 30 Mar 2018 7:55 AM

The variables used for .net work in VB, but not in NAV. Used another variable in place of .Selection and the function is now working.

Reply
Verified Answer
NYNavDev responded on 30 Mar 2018 7:55 AM

The variables used for .net work in VB, but not in NAV. Used another variable in place of .Selection and the function is now working.

Reply
Suggested Answer
Stefano Demiliani responded on 14 Feb 2018 2:49 PM

It seems a cast error. Are you sure that the selected element is exactly what you want? Is Word.selection the correct object you're casting?

Reply
Suggested Answer
Stefano Demiliani responded on 14 Feb 2018 3:42 PM

Strange... this seems a cast error or an object non initialized error.

Reply
Suggested Answer
Suresh Kulla responded on 14 Feb 2018 7:17 PM

In Standard NAV check the codeunit 5054 and see if there is anything helpful to achieve it.

Reply