I am getting "There is a printer error." when tying to send a print job to a printer using automation on Windows 7 with Word 2010. Same code works fine on Windows XP box with Word 2007. I am not sure if Windows 7 or word 2010 is causing the error.
Any help appreciated
using Microsoft.Office.Interop.Word;
.....
object oWordbasic = wordDoc.Application.WordBasic;
object[] argValues = new object[] { value, 1 }; //first arg is a printer name
String[] argNames = new String[] { "Printer", "DoNotSetAsSysDefault", };
//Error Here
oWordbasic.GetType().InvokeMember("FilePrintSetup", System.Reflection.BindingFlags.InvokeMethod, null, oWordbasic, argValues, null, null, argNames);
I get the Error Below
System.Reflection.TargetInvocationException was caught
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at PBP.ABC.Framework.Wrappers.Microsoft.Word.WordDocument.set_ActivePrinterName(String value) in
InnerException: System.Runtime.InteropServices.COMException
HelpLink=wdmain11.chm#24696
Message=There is a printer error.
Source=Microsoft Word
ErrorCode=-2146827168
InnerException:
If I leave out the printer parameters, the invoke work but not printing to the printer specified. It will print to the default printer.
Thanks.
Might work for you - this is what I had to do in Word to print without changing the active printer, I was getting an error and found that sometimes Word liked just the printer name and other times wanted to also have the port.
... to get the printer names and ports use InstalledPrinter as below
}
...then after instantiating Word I have something like this to set the printer: