VBA & Macro Problems

Excel VBA: Show a Confirmation Before SharePoint Check-In

Natalie TaylorNatalie Taylor Nov 12, 2026 869 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Open the ThisWorkbook module

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.

2
Insert the confirmation code

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

3
Save and test the event

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.

Enable macros before testing: The event procedure will not run if Excel disables macros. Check the security warning or use Excel Trust Center settings to allow macros for the workbook.
Free Microsoft Office alternative

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.

Familiar spreadsheet interface for editing and reviewing workbooksLightweight alternative for everyday document and spreadsheet tasksSupports common Microsoft Excel .xlsx and .xls formats for easier migrationHelps users continue working with Office-compatible files without a complex setup
microsoft office alternative - wps office

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.