PC Review


Reply
Thread Tools Rate Thread

Changing Sheet Names

 
 
=?Utf-8?B?TmV3VG9WQg==?=
Guest
Posts: n/a
 
      17th Jul 2007
I'm having trouble changing the names of my worksheets in my new workbook,
can someone help? Here is the code that I have. I'm using Visual Studio
2005, Excel 2007 and VB, here is some of the code I have. Thanks!

Dim LCV = New Excel._ExcelApplication
LCV = CreateObject("Excel.Application")
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oSheets As Excel.Sheets
Dim oSheet1 As Excel.Worksheet

oBooks = LCV.Workbooks
oBook = oBooks.Add()
oSheets = oBook.Worksheets <----I get an error saying COM unhandled
oSheet1 = oSheets.Add
oSheet1.Name = "Portfolio"


I know it already has 3 sheets when you create a new workbook, but how do
you change those names?


 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      17th Jul 2007

I don't have Visual Studio, Excel 2007 or VB,
however, here is my guess as to how it should read...

LCV = CreateObject("Excel.Application")
Dim oBook As LCV.Workbook
Dim oBooks As LCV.Workbooks
Dim oSheets As LCV.Sheets
Dim oSheet1 As LCV.Worksheet

oBooks = LCV.Workbooks
oBook = oBooks.Add()
oSheets = oBook.Sheets
oSheet1 = oSheets(1)
oSheet1.Name = "Portfolio"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"NewToVB"
<(E-Mail Removed)>
wrote in message
I'm having trouble changing the names of my worksheets in my new workbook,
can someone help? Here is the code that I have. I'm using Visual Studio
2005, Excel 2007 and VB, here is some of the code I have. Thanks!

Dim LCV = New Excel._ExcelApplication
LCV = CreateObject("Excel.Application")
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oSheets As Excel.Sheets
Dim oSheet1 As Excel.Worksheet

oBooks = LCV.Workbooks
oBook = oBooks.Add()
oSheets = oBook.Worksheets <----I get an error saying COM unhandled
oSheet1 = oSheets.Add
oSheet1.Name = "Portfolio"


I know it already has 3 sheets when you create a new workbook, but how do
you change those names?


 
Reply With Quote
 
shah shailesh
Guest
Posts: n/a
 
      18th Jul 2007
Besides you may try this as you have not properly set the objects in your
code.

Dim LCV as Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet1 As Excel.Worksheet

SET LCV = CreateObject("Excel.Application")
SET oBook = LCV.Workbooks.add
SET oSheet1 = oBook.Sheets.Add
oSheet1.Name = "Portfolio"


Regards,
Shailesh Shah
http://in.geocities.com/shahshaileshs/
(Excel Add-ins Page)
If You Can't Excel with Talent, Triumph with Effort.



"NewToVB" <(E-Mail Removed)> wrote in message
news:9F75F6A8-EC3E-4842-BAD3-(E-Mail Removed)...
> I'm having trouble changing the names of my worksheets in my new workbook,
> can someone help? Here is the code that I have. I'm using Visual Studio
> 2005, Excel 2007 and VB, here is some of the code I have. Thanks!
>
> Dim LCV = New Excel._ExcelApplication
> LCV = CreateObject("Excel.Application")
> Dim oBook As Excel.Workbook
> Dim oBooks As Excel.Workbooks
> Dim oSheets As Excel.Sheets
> Dim oSheet1 As Excel.Worksheet
>
> oBooks = LCV.Workbooks
> oBook = oBooks.Add()
> oSheets = oBook.Worksheets <----I get an error saying COM
> unhandled
> oSheet1 = oSheets.Add
> oSheet1.Name = "Portfolio"
>
>
> I know it already has 3 sheets when you create a new workbook, but how do
> you change those names?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Sheet Names Gavin Ling Microsoft Excel Programming 5 6th Jan 2006 05:58 PM
Changing Sheet Names and dates DAn Microsoft Excel Worksheet Functions 4 16th Apr 2004 10:55 PM
changing font/style of sheet names TRL Microsoft Excel Worksheet Functions 2 5th Feb 2004 12:14 PM
Linking to external workbooks with changing sheet names Sh0t2bts Microsoft Excel Worksheet Functions 4 13th Oct 2003 06:35 PM
changing sheet names Andy Healey Microsoft Excel Programming 2 12th Oct 2003 04:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:19 AM.