如果您只是想要一個簡單的單元格內是/不是下拉菜單,您只需聲明一個範圍併爲其添加驗證規則即可。微軟有一些關於here的文檔,但是與大多數互操作文檔相比,它有點稀疏......所以這裏是一個片段,顯示如何添加驗證列表:
'Imports Microsoft.Office.Interop.Excel
Dim xlApp As New Excel.Application
xlApp.Visible = True
Dim xlWorkbooks As Excel.Workbooks = xlApp.Workbooks
Dim xlWorkbook As Excel.Workbook = xlWorkbooks.Add
Dim xlWorksheet As Excel.Worksheet = CType(xlWorkbook.Worksheets(1), Excel.Worksheet)
Dim xlRng As Excel.Range = xlWorksheet.Cells(1, 1)
With xlRng.Validation
.Add(Type:=Excel.XlDVType.xlValidateList, _
AlertStyle:=Excel.XlDVAlertStyle.xlValidAlertStop, _
Operator:=Excel.XlFormatConditionOperator.xlBetween, _
Formula1:="Yes,No")
.IgnoreBlank = True
.InCellDropdown = True
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRng)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorksheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbooks)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)