Solved

Programmatically Creating/Deleting/Renaming Excel Worksheets

Posted on 2000-03-16
2
446 Views
Last Modified: 2008-02-20
I am currently developing a project in Access that takes data and stores it in arrays, and then spits out an Excel Report that can be edited.  What I need to be able to do is delete sheet2 and sheet3 from the newly created object and rename Sheet1.  The following is a snipet of code that I have been using.

   Set ExcelApp = New Excel.Application
   ExcelApp.Visible = True
     
   ExcelApp.Workbooks.Add
   Set Excelbook = ExcelApp.ActiveWorkbook
   
   Set ExcelSheet = Excelbook.Worksheets("Sheet2")

   ExcelSheet.Delete
   ExcelSheet.Activate

this works for deleting but Excel wants an answer if deleting is okay, is there a param I send send like I do when I save.  Also I would like to know how to change the Sheet name from Sheet1 to like Test1.  Thanks in advance, any help is greatly appreciated.

-John
0
Comment
Question by:jforbes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 2625014
What do you think about that?

Private Sub Command1_Click()
Dim ExcelApp As Excel.Application
Dim ExcelBook As Workbook
Dim intI As Integer

   Set ExcelApp = New Excel.Application
   ExcelApp.Visible = True
   
   ExcelApp.Workbooks.Add
   Set ExcelBook = ExcelApp.ActiveWorkbook
   
   ExcelApp.Application.DisplayAlerts = False
   For intI = ExcelBook.Worksheets.Count To 2 Step -1
        ExcelBook.Worksheets(intI).Delete
   Next intI
   ExcelApp.Application.DisplayAlerts = True

   ExcelBook.Worksheets(1).Name = "New Name"

End Sub
0
 
LVL 1

Author Comment

by:jforbes
ID: 2625136
Thanks Bro!! Works like a charm.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question