Be seen. Boost your question’s priority for more expert views and faster solutions
Dim dpl As New List(Of DatasetPair)
'Try
Me.Cursor = Cursors.WaitCursor
Dim intSheetCount As Integer = 0
For i As Integer = 0 To lvMatchedDvid.Items.Count - 1
Dim dp As New DatasetPair
dp.DataVersionIdOne = lvMatchedDvid.Items(i).Text.ToString
dp.DataVersionIdTwo = lvMatchedDvid.Items(i).SubItems(1).Text.ToString
intSheetCount += 1
dp.SheetId = intSheetCount
dpl.Add(dp)
Next
Dim wb As Excel.Workbook = Utilities.CreateWorkbook()
For Each dp As DatasetPair In dpl
Dim ws As New Excel.Worksheet
ws = GenerateWorksheet(dp)
MessageBox.Show(ws.Rows.Count.ToString)
wb.Worksheets.Add(ws)
Next
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
Message="Exception from HRESULT: 0x800A03EC"
Source="Microsoft.Office.Interop.Excel"
StackTrace:
at Microsoft.Office.Interop.Excel._Worksheet.Copy(Object Before, Object After)
at BADS.frmMultplePBTMR.btnGenerateReport_Click(Object sender, EventArgs e) in C:\Documents and Settings\jvelasqu\My Documents\Visual Studio 2008\Projects\BADS\BADS\frmMultplePBTMR.vb:line 254
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 BADS.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()
InnerException:
For Each dp As DatasetPair In dpl
Dim excelApp As New Excel.Application
Dim ws As New Excel.Worksheet
ws = GenerateWorksheet(dp)
ws.SaveAs(wb.Path.ToString)
Dim strSourceFilePath As String
strSourceFilePath = wb.Path.ToString & "\" & wb.Name.ToString
MessageBox.Show(strSourceFilePath)
'wb.Close()
Dim wbkDest As Excel.Workbook = excelApp.Workbooks.Open(strFilePath)
Dim wbkSource As Excel.Workbook = excelApp.Workbooks.Open(strSourceFilePath)
'ws.Copy(Before:=wbkDest.Worksheets.Count - 1)
ws.Copy(wbkDest.Worksheets(wbkDest.Worksheets.Count - 1))
Next
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
ws.copy wb.Worksheets(1)
for example.