Dim dlg As New OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.Workbook = App.WorkBooks.open(dlg.FileName)
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim rg As MSExcel.Range = ws.Columns(2) ) '设置第二列
Dim str As String = "选项1,选项2,选项3" '数据有效性的内容
rg.Validation.Delete()
rg.Validation.Add(MSExcel.XlDVType.xlValidateList, MSExcel.XlDVAlertStyle.xlValidAlertStop, MSExcel.XlFormatConditionOperator.xlNotBetween, str, Nothing)
rg.Validation.InCellDropdown = True
rg.Validation.IgnoreBlank = True
Wb.Save
Wb.Close
App.Quit
catch ex As Exception
msgbox(ex.message)
App.Quit
End try
End If