Net-informations.com
SiteMap  | About    

Excel Data Validation Input Message

Data Validation Input Messages is using to embed a message in cells in an Excel Spread Sheet. When we select that cell the message will display . It is very useful for data entry purpose for define the rules for entering data and also we can put a notes about the data in the cell. Through vb.net we can set a Data Validation Input Messages in Excel .

The follwong image shows how a Data Validation Input Message after embedded in an Excel cell.

vb.net_excel_data_validation_input_message.JPG



Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value
        Dim rangeCells As Excel.Range

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")

        xlWorkSheet.Range("B5", "D5").Validation.Add( _
        Type:=Excel.XlDVType.xlValidateInputOnly, _
        AlertStyle:=Excel.XlDVAlertStyle.xlValidAlertStop, _
        Operator:=Excel.XlFormatConditionOperator.xlBetween)
        xlWorkSheet.Range("B5", "D5").Validation.IgnoreBlank = True
        xlWorkSheet.Range("B5", "B5").FormulaR1C1 = "Click  Here " + _
        "to see Notes"
        xlWorkSheet.Range("B5", "D5").Validation.InputTitle = _
        "vb.net-informations.com"
        xlWorkSheet.Range("B5", "D5").Validation.ErrorTitle = "Error in Title"
        xlWorkSheet.Range("B5", "D5").Validation.InputMessage = "Here is " + _
        " the notes  embeded - you can enter 255 characters maximum in notes "
        xlWorkSheet.Range("B5", "D5").Validation.ErrorMessage = "Error in Notes"
        xlWorkSheet.Range("B5", "D5").Validation.ShowInput = True
        xlWorkSheet.Range("B5", "D5").Validation.ShowError = True

        xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

        MsgBox("File created !")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub
End Class

When you execute this source code you can find Input message in Cell.




net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.