My application was working fine. However, I needed to add some refinements which had nothing to do with the printing.
But now the code which printed a pdf copy of my EXCEL worksheet does not now work.
The code is
PrintForm1.PrinterSettings.PrinterName = "Microsoft Print to PDF"
PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter
If PrintForm1.PrinterSettings.IsValid Then
PrinterName = PrintForm1.PrinterSettings.PrinterName
oSheet.PrintOut(From:=1, To:=1, Copies:=1, ActivePrinter:=PrinterName, Collate:=True, Preview:=True)
I get this error message associated to the first line.
"System.NullReferenceException: 'Object reference not set to an instance of an object.'
MatchManagementApplication_2.InputForm.PrintForm1.get returned Nothing.
Any help greatly appreciated.
"
What I have tried:
I have Imported Microsoft.VisualBasic.PowerPacks.Printing but the code stated it was not required.
Changed to Microsoft.VisualBasic.PowerPacks then a new error message came up on the second line of code, stating Error BC30456 'PrintAction' is not a member of 'Microsoft.VisualBasic.PowerPacks.Printing'.
Commented out the second line of code but the first line still fails when the code is run.