Dim nVal As Integer
If Sheets(1).Range("A22500").Value = 3 Then
MsgBox "Não pode imprimir mais nenhuma vez!…"
Cancel = True
Exit Sub
Else
nVal = Sheets(1).Range("A22500").Value
nVal = nVal + 1
Sheets(1).Range("A22500").Value = nVal
MsgBox "Só pode imprimir mais!…" & 3 – nVal
End If
End Sub
Private Sub Workbook_Open()
For Each Ctrl In Application.CommandBars.FindControls(ID:=109) ' Faz o disable do ícone Print Preview
Ctrl.Enabled = False
Next Ctrl
For Each Ctrl In Application.CommandBars.FindControls(ID:=4) ' Faz o disable no Menu Ficheiro| Imprimir.
Ctrl.Visible = False
Next Ctrl
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each Ctrl In Application.CommandBars.FindControls(ID:=109) ' Faz o enable do ícone Print Preview
Ctrl.Enabled = True
Next Ctrl
For Each Ctrl In Application.CommandBars.FindControls(ID:=4) ' Faz o enable no Menu Ficheiro| Imprimir.
Ctrl.Enabled = True
Next Ctrl
End Sub
Tópicos relacionados:
- Números dos ID's de Controlo do CommandBar (Microsoft)
- Disable Command bars and controls in Excel 97-2003 (Ron de Bruin)
- Sample macros to return ID for a CommandBar control (Microsoft)
- Lists of Control IDs – Excel 2003 e 2007, para Download (Microsoft)
- Create menu for use in international environment distributed as xla (VbaExpress)