Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Programmatically Creating/Deleting/Renaming Excel Worksheets

Posted on 2000-03-16
2
Medium Priority
?
449 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 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