The solution is similar to the one I provided in this accepted answer: Attach a Javascript function to an OOTB ribbon button.
Here's the code, adopted for your case:
<CustomAction Id="TrackDownloadsAction" RegistrationType="List" RegistrationId="100" Location="CommandUI.Ribbon">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.List.Actions.ExportToSpreadsheet">
<Button
Id="Ribbon.List.Actions.ExportToSpreadsheet"
Sequence="40"
Command="ExportToSpreadsheetIfConfirmed"
Image16by16="/_layouts/15/$Resources:core,Language;/images/formatmap16x16.png?rev=23" Image16by16Top="-181" Image16by16Left="-73"
Image32by32="/_layouts/15/$Resources:core,Language;/images/formatmap32x32.png?rev=23" Image32by32Top="-239" Image32by32Left="-307"
LabelText="$Resources:core,cui_ButExportToSpreadsheet;"
ToolTipTitle="$Resources:core,cui_ButExportToSpreadsheet;"
ToolTipDescription="$Resources:core,cui_STT_ButExportListToSpreadsheet;"
TemplateAlias="o2"
/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="ExportToSpreadsheetIfConfirmed"
CommandAction="javascript:if (confirm('Are you sure want to export?')) SP.Ribbon.PageManager.get_instance().executeRootCommand('ExportToSpreadsheet', window.g_CUIcommandProperties, {CommandId: 'ExportToSpreadsheet'}, null);" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
This will replace OOTB "Export to Excel" button with the customized one for lists. If you need it for libraries, change RegistrationId
to 101 and Ribbon.List.Actions.ExportToSpreadsheet
to Ribbon.Library.Actions.ExportToSpreadsheet
(two places in the code).