.NET Error: Cannot convert 'Object' to 'Ref Object'

Posted by VIJI Wednesday, July 1, 2009

Problem Description:

The error Cannot convert 'Object' to 'Ref Object' occurs when using PrintOut method with the Word 10.0 Object model

When working with the Word 10.0 Object model, the method PrintOut requires the parameters to be 'ref object'.

The parameter for the PrintDocument() function requires an integer to be passed in.


Solution Description:

To provide the correct type for the Word PrintOut() method, create a local OBJECT variable and assign it to the parameter being passed in the function.

[CODE]

public void PrintDocument(int copiesToPrint)

{

//Creation of Local object variable
//Assignment of paramter

object _copiesToPrint = copiesToPrint;


//It will work properly
mobjWord.ActiveDocument.PrintOut(

ref MissingValue, ref MissingValue, ref MissingValue,

ref MissingValue, ref MissingValue, ref MissingValue,

ref MissingValue, ref _copiesToPrint, ref MissingValue,

ref MissingValue, ref MissingValue, ref MissingValue,

ref MissingValue, ref MissingValue, ref MissingValue,

ref MissingValue, ref MissingValue, ref MissingValue);

}

[/CODE]

0 Responses to .NET Error: Cannot convert 'Object' to 'Ref Object'

Post a Comment