Reputation: 2780
I am replacing excel cell values in C# with the following code, but in case if a particular field is not found then its showing following warning dialog box.
Code is like this:
xlWorkSheet.Cells.Replace(
"CustomerName",
"John",
missingValue,
missingValue,
missingValue,
missingValue,
missingValue,
missingValue);
So if "CustomerName" is not present in any of the excel cells it shows following message:
Microsoft Office Excel
Microsoft Office Excel cannot find any data to replace. Check if your search formatting and criteria are defined correctly. If you are sure that matching data exists in this workbook, it may be on a protected sheet. Excel cannot replace data on a protected worksheet.
I need to stop this dialog box to popup, because I have many cells that can have fields or not.
Any answer?
Upvotes: 2
Views: 3320
Reputation: 51
Application.DisplayAlerts = False
and turn back on afterwards:
Application.DisplayAlerts = true
Upvotes: 5
Reputation: 481
Can you check for the "CustomerName" value first in the worksheet?
Quick google search found this: http://msdn.microsoft.com/en-us/library/e4x1k99a(v=vs.80).aspx
If you have a value in the same worksheet, call the replace code and no dialog shows.
Upvotes: 2