Macro

W

Waleed Abbass

I need to creat a macro to disable the print command until the user enter some data in the range of cells, Please HEL

Thanks
 
D

Dave Peterson

You could use a workbook event.

Rightclick on the excel icon to the left of File (on the worksheet menu bar).

Select view code and paste this in:

Option Explicit

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim myRng As Range

Set myRng = Me.Worksheets("sheet1").Range("a1:a3,c9,d14")

If myRng.Cells.Count <> Application.CountA(myRng) Then
MsgBox "Please complete those cells!"
Cancel = True
End If

End Sub

Modify the sheetname and addresses to your liking.

(if the user disables macros or disables events, then it won't stop them. In
fact, if they copy the worksheet to another workbook or copy the cells to a
different worksheet, it won't stop them. But it should stop most.)
 
F

Frank Kabel

Hi
you could use the BeforePrint event of your workbook. e.g. put the
following code in your workbook module 8not in a standard module):
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim rng As Range
Dim wks As Worksheet

Set wks = Me.Worksheet("Sheet1")
Set rng = wks.Range("A1")
If rng.Value = "" Then
MsgBox "cell A1 of sheet1 has to be filled"
Cancel = True
End If
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Waleed Abbass said:
I need to creat a macro to disable the print command until the user
enter some data in the range of cells, Please HELP
 
Top