VB6 and Creating and Excel spreadsheet

Posted on 2005-04-15
Last Modified: 2010-05-02
Hi Everyone,
i'm trying to create an excel spreadsheet which only has 1 sheet (the normal default is 3 sheets).  I have tried to remove the extra two sheets, but Excel generates a warning when you try to delete the sheet, and I don't want my customer to have to worry about the warning.  I'm going to be adding sheets (which I can do without problems), sheet 1 will be a title page, then I will be adding 1 new sheet for each item in a database, and I don't want those extra two sheets in the workbook.  Does anyone have any ideas about this?  Thanks in advance for your help.
Question by:TopCatOnyx
    1 Comment
    LVL 35

    Accepted Solution

    Hi TCO,

    There are a couple of ways you can accomplish this.
    For all of this, it assumes xl is your application variable
    Set xl = Excel.Application

    If you use
     xl.Workbooks.Add 1
     xl.Workbooks.Add -4167
    These will create a standard workbook with only 1 sheet in it.

    You can remove the warning of deleting the sheets using xl.DisplayAlerts = False / True, like:
     xl.DisplayAlerts = False
     For i = xl.SheetsInNewWorkbook To i Step -1
     Next i
     xl.DisplayAlerts = True

    (the xl.SheetsInNewWorkbook property should be used instead of 3, not all users use 3)

    Any questions, let me know!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    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…
    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…

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now