我有一个excel文件和一个在visual studio 2013中创建的表单。使用表单将数据插入excel文件中。现在,多个用户将通过公共驱动器同时使用此文件和表单。现在,问题是当我共享文件并在表单中输入数据并单击提交按钮将表单中的数据传输到Excel时,会发生错误:
“您的应用程序中发生了未处理的异常。如果您单击继续,应用程序将忽略该错误并尝试继续。如果您单击退出,应用程序将立即关闭。来自HRESULT的异常:0x800A03EC”
编辑:这是我的代码:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
xlWorkBook = xlApp.Workbooks.Open("C:\Users\test.xlsx")
'xlApp.Visible = True
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
xlworksheet1 = xlWorkBook.Sheets("Sheet2")
xlWorkSheet.Unprotect()
Dim iRow As Long
iRow = 1
With xlWorkSheet
Do While .Cells(iRow, 2).value <> ""
.Cells(iRow, 2).activate()
iRow = iRow + 1
Loop
.Cells(iRow, 2).Value = Me.t1.Text
.Cells(iRow, 3).Value = Me.t2.Text
.Cells(iRow, 5).Value = Me.t3.Text
.Cells(iRow, 7).Value = Me.t4.Text
.Cells(iRow, 10).Value = Me.t5.Text
.Cells(iRow, 13).Value = Me.t6.Text
.Cells(iRow, 14).Value = Me.t7.Text
.Cells(iRow, 20).Value = Me.t8.Text
End With
Me.t1.Text = ""
Me.t2.Text = ""
Me.t3.Text = ""
Me.t4.Text = ""
Me.t5.Text = ""
Me.t6.Text = ""
Me.t1.Focus()
xlApp.DisplayAlerts = False
xlWorkSheet.Protect()
xlWorkBook.Save()
xlWorkBook.Close()
End Sub
我该如何纠正?请帮忙!