カスタムテキストを使用してExcelセルの検証を行うための次のコードがあります。
var cellValues = activeSheet.Range[columnLetterValue + startingRow, Type.Missing];
cellValues.Validation.Add(XlDVType.xlValidateCustom, XlDVAlertStyle.xlValidAlertInformation, XlFormatConditionOperator.xlBetween, cellValues.Value2, Type.Missing);
cellValues.Validation.IgnoreBlank = true;
cellValues.Validation.ErrorTitle = "Custom error title";
cellValues.Validation.ErrorMessage = "Custom error message description";
cellValues.Validation.ShowError = true;
cellValues.Validation.ShowInput = false;
行をデバッグしてErrorTitleまたはErrorMessageを設定すると、a'System.Runtime.InteropServices.COMException'
がスローされます。
スタックトレース:
{System.Runtime.InteropServices.COMException(0x800A03EC):HRESULTからの例外:
System.RuntimeType.ForwardCallToInvokeMember(String memberName、BindingFlags flags、Object target、Int32 [] aWrapperTypes、MessageData&msgData)atMicrosoft.Office.Interop.Excel
。 Validation.set_ErrorTitle(String)
私はオンラインで調べて、これが可能であることを示すいくつかの例を見つけました: C#を使用したExcelでの範囲検証
Excelでマクロを記録したこともあり、「VBA」と同等のコードで動作します。
ActiveCell.FormulaR1C1 = "Custom"
Range("A1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertInformation, _
Operator:=xlBetween, Formula1:="Custom"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "UDF Title"
.InputMessage = ""
.ErrorMessage = "The message"
.ShowInput = False
.ShowError = True
End With
End Sub
XlDVTypeとXlFormatConditionOperatorのさまざまな組み合わせも試しましたが、カスタムメッセージボックステキストの設定に違いは見られませんでした。
カスタムErrorTitleとErrorMessageを使用して検証ルールを設定する方法を知っている人はいますか?