- 1). Open your Excel workbook you are working on.
- 2). Click "Developer" on the toolbar, then click and drag where you want the checkbox to be placed. Right-click the check box and click "Format Control." Click the "Cell link" field, then choose a cell on your spreadsheet. As an example, select "A1." Click "OK." Whenever you check this checkbox, the cell A1 will display "TRUE" and when it is unchecked it will display "FALSE."
- 3). Press "Alt"+"F11" to open the Visual Basic editor in Excel. Double-click "Thisworkbook" on the side, to insert the following macro into the whole workbook.
- 4). Copy and paste the following macro:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("sheet1").Range("a1").Value = "FALSE" Then Cancel = True
End Sub
This stops the workbook from closing if cell A1 on 'sheet1' displays "FALSE" -- as it will until the checkbox is ticked. - 5). Press "ALT"+"F11." Then click "File," then "Save," then "Close."
next post