How to detect the print preview window of Excel 2003, with vb.net?
I need to be able to test if the current view is print preview in Excel 2003.
Is there something in the excel object model to simply access this property? (Like the application.printprevie开发者_开发知识库w in the Word object model...).
Any advice would be more than welcome,
Thanks
Julien
PS: Long story short, I'm developing a vsto addin with keyboard short-cuts to my custom functions, and I need to disable this shortcuts when print preview is on.
You'll want to determine if it is in xlPageBreakPreview
If Windows(1).View = xlPageBreakPreview Then
''# do your thing
End If
Note that Windows(1)
always means "the active view".
EDIT: Re-read the question and saw you meant the actual print preview window. That is a dialog of Application.Dialogs(xlDialogPrintPreview)
. It's only method is .Show
. But it wouldn't really matter as code doesn't run when that dialog is open. It will only return two values - True
and False
. So True
means something was printed and False
means the dialog was closed without printing. You can return the value by doing something like this:
dlgPrinted = Application.Dialogs(xlDialogPrintPreview).Show
If dlgPrinted Then
Debug.Print "The worksheet was printed"
Else
Debug.Print "The user closed print preview without printing."
End If
精彩评论