To achieve the function is, click A button, can put the files in A selected few worksheet merger is inserted into the current file sheet1, but the runtime error: Exception thrown: 'System.Runtime.InteropServices.COM Exception in ExcelTemplate5. DLL
HResult=0 x800a03ec Message=Exception from HResult: 0 x800a03ec
Source=& lt; Always evaluate the exception source>
StackTrace: & lt; Always evaluate the exception stack trace>
Including ExcelTemplate5 is the project name, this is a VSTO EXCEL template project, not EXCEL plug-in,
Button code:
Public Class FrmMain
Private Sub BtnImportIO_Click (sender As Object, As EventArgs e) Handles BtnImportIO. Click
If LstbxIO. SelectedIndex=1 Then
MsgBox (" No item is selected!" )
The Else
XlApp. ScreenUpdating=False
ThisWbk=xlApp ThisWorkbook 'this step wrong
ThisWst=thisWbk. Worksheets (" IO_List ")
XlApp=New Excel. Application With {. Visible=False}
Dim wbkFile As Excel. The Workbook=xlApp. Workbooks. Open (strFilePath)
IntTLastRow=1
'For loop combine several worksheet in A file selected is inserted into the current file sheet1, For there is wrong, you don't post out,
WbkFile. Close (SaveChanges:=0)
WbkFile=Nothing
LstbxValidation. Items. The Add (" Import completed. ")
Application.doevents ()
XlApp. ScreenUpdating=True
End the if
End Sub
The End of the Class
XlApp defined in Module1, but don't know why bad to use,
Imports. Microsoft Office. Interop. Excel
Imports. Microsoft Office. Tools. Excel
The Public Module Module1
Public strFilePath As String 'Store the full path of the source file (the file to be imported)
Public xlApp As Excel. Application=Globals. ThisWorkbook. Application
. Public thisWbk As Excel Workbook
Public thisWst As Excel. The Worksheet
End the Module