|
-
Oct 23rd, 2007, 10:47 AM
#1
Thread Starter
PowerPoster
Excel API Sheets.Move trashes workbooks
Any ideas on how to fix this or make it work correctly?
I have 2 workbooks.
1 is the workbook that counts many worksheets
the other is a workbook with 1 worksheet.
I want to move the workbook that contains 1 worksheet into the other workbook which has alot of worksheets, but when i do this it seems to trash the workbook that contains many sheets, in that i cannot access any properties of the workbook instance, it gives me COMException, and thats it.
Before I move it, its fine but after, it gives me COMException when accessing the application property or any other properties but DOES succeed in moving....
-
Oct 23rd, 2007, 11:04 AM
#2
Re: Excel API Sheets.Move trashes workbooks
You shouldnt be using the child application property of Excel. Also, your terminology is confused with workbook and worksheet. A workbook contains one or more worksheets. A worksheet can only be a child/contained in a workbook.
So it sounds like you want to move a sheet from one workbook into another?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 23rd, 2007, 11:16 AM
#3
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
Thanks, sorry, it's been a long hard day
I think i fixed it, instead of MOVE, did a COPY and that seems to fix the problem. I can get hold of the InputWorkbook (the workbook that contains many worksheets) after doing a copy, but not after a move.
-
Oct 23rd, 2007, 11:42 AM
#4
Re: Excel API Sheets.Move trashes workbooks
Oh also, if your sheet to be "moved" is the only sheet in the workbook then it will fail too because you always need at least one worksheet in a workbook at all times.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 23rd, 2007, 11:59 AM
#5
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
Thanks. thats probably why.
a quick one....
how can I find a worksheet thats been copied from a workbook to another by the name of that worksheet?
-
Oct 23rd, 2007, 12:04 PM
#6
Re: Excel API Sheets.Move trashes workbooks
Yes, you can use the Sheets collection by simply referencing the name of the sheet.
oBook.Sheets("My sheet").Activate
or such. If you want to determine if it exists first before that you can loop through the Sheets collection looking for a match.
If oBook.Sheets(x).Name = "My Sheet" Then
'Found
Exit For
End If
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 23rd, 2007, 01:35 PM
#7
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
Thanks
I did try this but this did not work. It just threw a COM Exception. I will try again later but wondering what else to do.
-
Oct 23rd, 2007, 01:51 PM
#8
Re: Excel API Sheets.Move trashes workbooks
Whats the exception state?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 24th, 2007, 05:06 AM
#9
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
Exception state:
{"Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"}
-
Oct 24th, 2007, 05:06 AM
#10
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
Exception state:
{"Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"}
But I have seen it copy the worksheet into the main workbook and can see the name of that worksheet being the exact same one as I extracted from its original workbook.
I see that the sheets collection remain the same of the "master" workbook even after copying over the sheet from the other workbook
Last edited by Techno; Oct 24th, 2007 at 06:30 AM.
-
Oct 24th, 2007, 10:08 AM
#11
Thread Starter
PowerPoster
Re: Excel API Sheets.Move trashes workbooks
fixed the problem. such a headache.
seemed that it was copying the main workbook to the other workbook, so it was doing it the other way around.
-
Oct 30th, 2007, 03:07 AM
#12
Re: Excel API Sheets.Move trashes workbooks
Doh! Well at least its working now
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|