Solved

Programmatically Creating/Deleting/Renaming Excel Worksheets

Posted on 2000-03-16
2
442 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
2 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 100 total points
Comment Utility
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
Comment Utility
Thanks Bro!! Works like a charm.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now