ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Print From Macro Only (https://www.excelbanter.com/excel-programming/328008-print-macro-only.html)

pete

Print From Macro Only
 
I want to restrict the users from using the file/print and only be able to
print from a macro. I saw this somewhere where you disable the print before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I think.

Bob Phillips[_6_]

Print From Macro Only
 
There is a BeforePrint event where you can test a global variable which you
set in code

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not fFromCode Then
Cancel = True
fFromCode = False
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pete" wrote in message
...
I want to restrict the users from using the file/print and only be able to
print from a macro. I saw this somewhere where you disable the print

before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I

think.



Bob Phillips[_6_]

Print From Macro Only
 
Small error

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not fFromCode Then
Cancel = True
End If
fFromCode = False
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bob Phillips" wrote in message
...
There is a BeforePrint event where you can test a global variable which

you
set in code

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not fFromCode Then
Cancel = True
fFromCode = False
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pete" wrote in message
...
I want to restrict the users from using the file/print and only be able

to
print from a macro. I saw this somewhere where you disable the print

before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I

think.





William[_2_]

Print From Macro Only
 
Hi Pete

Place the following code in the "ThisWorkBook" module....
Private Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Please use the 'PrintActiveSheet' macro"
Cancel = True
End Sub

Place the following code in a general module....
Sub PrintActiveSheet()
Application.EnableEvents = False
ActiveSheet.PrintOut
Application.EnableEvents = True
End Sub

To print the active sheet run the "PrintActiveSheet" macro.
--

-----
XL2003
Regards

William



"Pete" wrote in message
...
I want to restrict the users from using the file/print and only be able to
print from a macro. I saw this somewhere where you disable the print
before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I
think.




Jim Thomlinson[_3_]

Print From Macro Only
 
Bob...

What version of Excel is that event first introduced?

"Bob Phillips" wrote:

There is a BeforePrint event where you can test a global variable which you
set in code

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not fFromCode Then
Cancel = True
fFromCode = False
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pete" wrote in message
...
I want to restrict the users from using the file/print and only be able to
print from a macro. I saw this somewhere where you disable the print

before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I

think.




Dave Peterson[_5_]

Print From Macro Only
 
xl97.

Jim Thomlinson wrote:

Bob...

What version of Excel is that event first introduced?

"Bob Phillips" wrote:

There is a BeforePrint event where you can test a global variable which you
set in code

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not fFromCode Then
Cancel = True
fFromCode = False
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pete" wrote in message
...
I want to restrict the users from using the file/print and only be able to
print from a macro. I saw this somewhere where you disable the print

before
and only allow the user to print from a macro.

I can not find it. It went something like setting a global varible I

think.




--

Dave Peterson


All times are GMT +1. The time now is 06:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com