Hi,
handle the WorkbookBeforeSave event (fired for a preview
as well as for print).
In case you are new to event handling in VBA: You need to
create a class module with a reference to the object
instance which events you are handling (in this case an
instance of the Excel application). The following snippet
should get you started:
' --- Class module AppEvents
Dim WithEvents app as Excel.Application
Sub Class_Initialize()
Set app = Application
End Sub
Sub app_WorkbookBeforePrint(wb As Workbook, Cancel As
Boolean)
MsgBox "Workbook named " & wb.Name & " will print."
End Sub
'-- In any standard module
Dim eventHandlerObj As New AppEvents
When your standard module is parsed, eventHandlerObj is
assigned a new instance of the AppEvents class module.
That fires the Class_Initialize in the class module,
assigning the private field app to the current application
instance. Subsequently, when Excel is about to print or
preview, the beforeprint event fires. You can cancel
printing by setting the parameter Cancel to false in the
handler.
Hope this is helpful. Best regards,
Dag Johansen
-----Original Message-----
hi there!!! i am working on a project that i need to know
if the user
has hit the print preview button to print preview a page.
the main idea is this. the user is asked to write
something and then
print preview the worksheet he has made the change and
LEAVE THE ACTIVE
WINDOW IN THE PRINT PREVIEW MODE.
as you know when the active window is in the print
preview mode nothing
runs behind-in the vba editor. i mean if you change back
to the vba
editor while in print preview mode and hit the f5 button
it will
freeze.
what i am thinking is this: there must be an event(hope
so) that we can
check if the user has hit the print preview button.
then capture the event and if the user has hit the
preview buttonh gets
a correct answer otherwise he fails.
this is a workaround. i do not know how to capture that
event or if
VB
gives me access to these events programatically.
please help
------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from
http://www.ExcelForum.com/
.