friendship.ani
New member
- Joined
- Aug 14, 2008
- Messages
- 3
- Programming Experience
- 1-3
hi,
I want to open a existing worksheet .Copy some data from it and put it in a new excel sheet and then close the existing worksheet .After that i want to open another workshhet and use it.
But i am getting
Code in manip.vb file
please help me with this
Thanks
I want to open a existing worksheet .Copy some data from it and put it in a new excel sheet and then close the existing worksheet .After that i want to open another workshhet and use it.
But i am getting
Code in file exl.vb:"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 461
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()
"
VB.NET:
Public Sub New(ByVal file As String) 'filename with entire path use open file dialog for ease of use
excelapp = New Microsoft.Office.Interop.Excel.Application
xlBooks = excelapp.Workbooks
excelWrkbk = xlBooks.Open(file)
excelSht = excelWrkbk.Sheets
excelWrkSht = excelSht(1)
excelapp.ScreenUpdating = False
excelapp.DisplayAlerts = False
End If
End Sub
VB.NET:
Private Sub loadexcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loadexcel.Click
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()
ExcelDoc = Nothing
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ExcelDoc = New ExcelEx(OpenFileDialog1.FileName)
---WHEN I CALL NEW IMMEDIATELY THE CONTROL MOVES TO THE exl.vb FILE AND THEN
SHOWS THE ERROR MESSAGE IN BELOW LINE
excelWrkbk = xlBooks.Open(file)
Thanks
Last edited by a moderator: