Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Changing Sheet Names
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Changing Sheet Names
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" 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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Changing Sheet Names
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" 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Using Sheet names & Workbook names in VBA coding | Excel Programming | |||
Changing Sheet Names | Excel Programming | |||
Changing VB Component Names to match Worksheet names using VBE | Excel Programming | |||
return all worksheet tab names and chart sheet tab names in report - an example | Excel Programming | |||
changing sheet names | Excel Programming |