为什么printform1不工作? [英] Why is printform1 not working?

查看:95
本文介绍了为什么printform1不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请工作正常。但是,我需要添加一些与打印无关的改进。

但是现在打印我的EXCEL工作表的pdf副本的代码现在不起作用。

代码是

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)





我收到与第一行相关的错误消息。

System.NullReferenceException:'对象引用未设置为对象的实例。'



MatchManagementApplication_2.InputForm.PrintForm1.get返回Nothing。

非常感谢任何帮助。





我尝试了什么:


我已导入Microsoft.VisualBasic.PowerPacks.Printing但代码声明它不是必需的。

更改为Microsoft.VisualBasic.PowerPacks然后在第二行代码上出现了一条新的错误消息,说明错误BC30456'PrintAction'不是'Microsoft.VisualBasic.PowerPacks.Printing'的成员。

注释掉第二行代码,但代码运行时第一行仍然失败。



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.

推荐答案

System.NullReferenceException 是我们在此处报告的最常见错误之一。这意味着您正在尝试使用尚未初始化的对象引用。找出位置和原因的唯一方法是使用调试器逐步执行代码。
System.NullReferenceException is one of the most common errors we see reported here. It means that you are trying to use an object reference that has not been initialised. The only way to find out where and why is to use your debugger to step through your code.


这篇关于为什么printform1不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆