friendship.ani 0 Newbie Poster

hi,
I open a Existing excel sheet and do something and then want to close this excel sheet and open a new excel sheet and work on it.

Code:manip.vb
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ExcelDoc = New ExcelEx(OpenFileDialog1.FileName)
Else
Exit Sub
End If
ExcelDoc.close()
GC.Collect()
Me.Show()
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ExcelDoc = New ExcelEx(OpenFileDialog1.FileName)---WHEN I CREATE A INSTANCE THE SECOND TIME THEN I GET THE BELOW ERROR IN excelWrkbk = xlBooks.Open(file) LINE IN excelsheet.vb FILE
Else
Exit Sub
End If

Code:excelsheet.vb
Public Sub New(ByVal file As String)
excelapp = New Microsoft.Office.Interop.Excel.Application
xlBooks = excelapp.Workbooks '.Open(file)
If Dir(file) <> "" Then
excelWrkbk = xlBooks.Open(file)
excelSht = excelWrkbk.Sheets
excelWrkSht = excelSht(1)
excelapp.ScreenUpdating = False
excelapp.DisplayAlerts = False
End If
End Sub


System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
HelpLink="C:\Program Files\Microsoft Office\Office12\1033\XLMAIN11.CHM"
Message="_Open method of Workbooks class failed"
Source="Microsoft Office Excel"
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Excel.Workbooks.Open(Object Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter)
at EAMS.ExcelEx..ctor(String file) in E:\Attendance\EAMS\EAMS\ExcelEx.vb:line 43
at EAMS.Manipulation.btnloadexcel_Click(Object sender, EventArgs e) in E:\Attendance\EAMS\EAMS\Manipulation.vb:line 460
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at EAMS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
please help me with this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.