SBX - Search With Button

SBX - Forum Post Title

Outlook Interop

Microsoft Dynamics NAV Forum

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

Question Status

Verified

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

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
My Badges

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

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

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

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

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

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
NYNavDev responded on 30 Mar 2018 7:55 AM
My Badges
Verified Answer

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

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

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

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

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

Reply

SBX - Two Col Forum

SBX - Migrated JS