If you’re automating Excel via the ActiveX/COM objects, you may notice an annoying msgbox saying
This action will cancel a pending refresh data command. Continue?
you can disable it via
Application.DisplayAlerts = False
Or if you’re actually instantiating an object from outside of Excel VBA (e.g. from a C# console app), try
Excel.Application ExcelObj = new Excel.Application();
ExcelObj.DisplayAlerts = false;