第3行返回COMException。 oBooks.GetType()。调用...
Dim oBooks As Microsoft.Office.Interop.Excel.Workbook = Me.fOpenXlsFile(strXLSFile)
Dim ci As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
oBooks.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod, Nothing, oBooks, Nothing, ci)
For i As Int32 = 0 To objLv.Items.Count - 1
oBooks.Styles.Item(i + 1).Interior.Color = objLv.Items(i).BackColor
Next
oBooks.Save()
答案 0 :(得分:3)
您正在尝试将工作簿添加到另一个工作簿。您需要将其添加到Workbooks集合中。这样的事情应该有效:
Dim wbs As Excel.Workbooks = oBooks.Application.Workbooks
wbs.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod, Nothing, wbs, Nothing, ci)