|
-
Feb 18th, 2005, 03:42 PM
#1
Thread Starter
Member
copying excel sheets
If I use the following code to copy a sheet of an excel file :
Sheet,application.worksheets("oldname").copy _
after:=Sheet.application.worksheets("oldname")
the result is O.K.!! : a new sheet (copy of the oldsheet) with the name oldname(2)
But now if either I want to copy oldname(2) to a new sheet or to rename oldname(2) using function renamesheet the result is error "9" (subindex out of the interval). It looks as if the code does not understand a sheet whose name is "oldname(2)". Ir doesn't understand the parenthesis (2). Any help? Thanks
-
Feb 18th, 2005, 04:35 PM
#2
Re: copying excel sheets
I think it may have to do with the way your referring to it. You dont need to use the application object.
A shorter way to reference the sheets is by using the sheets collection. Btw, I tried to simulate it but
it worked fine on my Excel 2003 version. It would make a new copy and name it sheet(x) where x is the
count of sheets in the workbook. Try something like this anyways.
VB Code:
Sheets(1).Copy After:=Sheets("Sheet(4)")
Sheets(Sheets.Count).Name = "Sheet" & Sheets.Count
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
|