Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.printing,microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default [how to] VBA catching close/print in printpreview

(sorry for the cross-posting)
<this could be useful

I found no answer [other than Leo Huser] searching for in posts to several news groups [since 1997]
on how to take PrintPreview in vba-control [an easy manner], so...
The ONLY way "to control" PrintPreview is... = not to use PrintPreview!!! <= [as method]
instead, it should be used [e.g.] = "UserResponse = Application.Dialogs(xlDialogPrintPreview). Show"
given that showing a BuiltInDialog it will return False if canceled by the user [or by code]
also, due to _BeforePrint event will be twice triggered [when "first-showing" PrintPreview]
there will be necessary other [public boolean] variables "as support".

Note: within _BeforePrint event, if Cancel is set to True, it will be "same-treated" = Canceled by user [or code]

=== in a normal code module ===
' to detect if the process is "by code" or "normal" _
and if the user [or code] cancels PrintPreview / Print '
Public ViewByCode As Boolean, _
PrintByCode As Boolean, _
PrintedByCode As Boolean

' Test_macro '
Sub My_Preview()
MsgBox "Starting PrintPreview [by code]..." ' <= this is optional '
ViewByCode = True
PrintedByCode = Application.Dialogs(xlDialogPrintPreview).Show
PrintByCode = False
If Not PrintedByCode Then
MsgBox "User [maybe code?] has CANCELED [print / preview]."
End If
End Sub

=== in ThisWorkbook code module ===
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ViewByCode Then
ViewByCode = False
PrintByCode = True
ElseIf PrintByCode Then
MsgBox "Printing process [can be] controlled by code..."
Else
MsgBox "Printing process is [should it be?] ""normal""..."
End If
End Sub

__HTH__
Regards,
Héctor.
MS-MVP [Mexico]


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PrintPreview Gerry Verschuuren Excel Discussion (Misc queries) 5 October 23rd 07 06:24 PM
MACRO: Catching only filled cell data sumit Excel Discussion (Misc queries) 1 November 24th 06 12:28 PM
CATCHING DUPLICATE INFORMATION IN DIFFERENT CELLS SAME PROGRAM Lisa Setting up and Configuration of Excel 1 July 20th 06 05:21 PM
Print before close Renato8 Excel Discussion (Misc queries) 2 April 28th 06 09:03 PM
ActiveX Controls moving upon print/printpreview Steven Cheng Excel Discussion (Misc queries) 6 February 2nd 05 03:31 AM


All times are GMT +1. The time now is 04:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"