Excel VBA: Show a Confirmation Before SharePoint Check-In
Question details
The user needs Excel to request confirmation before checking a workbook into SharePoint and to stop the process when the user chooses No.
- Product
- Microsoft Excel VBA with SharePoint document check-in
- Device & OS
- not provided
- Scenario
- A workbook is being checked into SharePoint, and a confirmation message must appear before the check-in continues.
- Observed behavior
- The desired behavior is a Yes/No confirmation dialog before check-in, with the check-in canceled when No is selected.
Save the workbook as a macro-enabled Excel file, such as .xlsm, and confirm that macros are enabled in Excel. Open the VBA editor and locate the ThisWorkbook module before adding the event procedure.
Add a Workbook_BeforeCheckin confirmation event in Excel VBA
Use this solution when every SharePoint check-in for the workbook should require an explicit Yes or No response.
The Workbook_BeforeCheckin event runs immediately before Excel checks the document into SharePoint. Setting Cancel to True prevents the check-in from proceeding when the user selects No.
In Excel, press Alt+F11 to open the Visual Basic Editor. In Project Explorer, expand the workbook project, double-click ThisWorkbook, and select Workbook from the left procedure list and BeforeCheckin from the right procedure list.
Paste this procedure into the ThisWorkbook module: Private Sub Workbook_BeforeCheckin(Cancel As Boolean) Dim response As VbMsgBoxResult response = MsgBox("By checking in, you confirm that you have reviewed the specific guidelines for this document. Click Yes to continue or No to cancel the check-in process.", vbYesNo + vbExclamation, "Confirmation") If response = vbNo Then Cancel = True End Sub
Press Ctrl+S and keep the file in a macro-enabled format. Return to Excel, start the SharePoint check-in command, and select Yes to continue or No to cancel the check-in.
Switch to WPS Office for lightweight spreadsheet work
WPS Office is a free, lightweight Microsoft Office alternative with a familiar spreadsheet interface and support for common Excel file formats. It can help with everyday workbook editing and migration, while Excel remains the appropriate tool for this specific SharePoint VBA event workflow.

Frequently Asked Questions
Where should the Workbook_BeforeCheckin code be placed?
Place it in the ThisWorkbook module, not in a standard VBA module or a worksheet module. In Excel, press Alt+F11, expand the workbook project, and double-click ThisWorkbook.
How does the VBA code cancel the SharePoint check-in?
The event receives a Cancel argument. When the user selects No, the code sets Cancel = True, which stops Excel from completing the check-in.
Why does the confirmation message not appear?
The workbook may not be saved as .xlsm, macros may be disabled, or the procedure may be in the wrong module. Confirm that the code is in ThisWorkbook and enable macros before testing.
Can I change the confirmation message and dialog title?
Yes. Edit the first quoted message in the MsgBox function to change the prompt, and replace "Confirmation" with the title you want displayed in the dialog.




