2

I am writing a macro to extract XML data from a Web API into a spreadsheet. The first column contains two fields delimited with a comma so I have extended the macro to insert a column then run Text to Columns to split out the data.

The macro works really well, but I get an annoying warning asking if I want to replace the data:

enter image description here

Is there a way to suppress the warning?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Spionred
  • 797
  • 2
  • 10
  • 27

3 Answers3

9

source: SolutionSite

To suppress the warnings:

Application.DisplayAlerts = False

To activate the warnings:

Application.DisplayAlerts = True
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Synoon
  • 2,297
  • 4
  • 22
  • 37
1
Application.DisplayAlerts = False

Two important points from the documentation:

[...] when a message requires a response, Microsoft Excel chooses the default response.

and

If you set [DisplayAlerts] to False, Microsoft Excel sets [it back] to True when the code is finished [...]

meaning you'll still have the standard "Do you want to save before closing?" etc. prompts during normal Excel use.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
1

I found a scenario where neither Application.DisplayAlerts = False nor Application.AlertBeforeOverwriting = False work.

When running some of the Data Analysis Add-In tools the messaging is bypassed. Whilst not ideal, I found a solution from prsthlm whereby one uses Application.SendKeys "{ENTER}" before the Run method call to handle the overwrite pop-up. E.g.

Pseudo code:

With Application
    .SendKeys "{ENTER}"
    .Run "ATPVBAEN.XLAM!Histogram", range1  _
    , range2, range3, False, _
    True, True, False
End With
QHarr
  • 83,427
  • 12
  • 54
  • 101