Solved

How to delete specific sheet from a excel workbook from access

Posted on 2013-01-13
4
485 Views
Last Modified: 2013-01-14
Hi,

I have an excel workbook which contain some data.
After upload a table data to an excel workbook and copy the data to specific worksheet of the same exce workbook, want to delete the sheet with data from access table.
for example I have test.xls and sheet1 named as "updated data" sheet2 is blank and sheet3 named "tbluploaded".
After I moved all necessary data from sheet3 to sheet1 I want to delete sheet2 and sheet3.
and do not want any warning message while deleting the sheets from the excel workbook.

the step are as below:
My VBA code export data to the workbook and which added as sheet3(tbluploade) then
open the excel workbook and copy necessary data to sheet1(updated data) then close the excel workbook.
Finally, I want to delete all sheet except sheet1(updated data).
Please advise me the VBA code to do that.

Thanks for your help.
0
Comment
Question by:alam747
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 38772374
here sample code to do that


Dim xlObj As Object
Set xlObj = CreateObject("excel.application")
    xlObj.workbooks.Open CurrentProject.Path & "\test.xlsx"
    With xlObj
        .worksheets("tbluploaded").Delete
        .worksheets("sheet2").Delete
    End With
    xlObj.activeworkbook.Save
    xlObj.Quit
    Set xlObj = Nothing
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38772944
No points, please :)

You should probably also turn off Excel alerts:

Dim xlObj As Object
Set xlObj = CreateObject("excel.application")
xlobj.DisplayAlerts = False
    xlObj.workbooks.Open CurrentProject.Path & "\test.xlsx"
    With xlObj
        .worksheets("tbluploaded").Delete
        .worksheets("sheet2").Delete
    End With
    xlObj.activeworkbook.Save
xlobj.DisplayAlerts = True
    xlObj.Quit
    Set xlObj = Nothing
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38773191
;-)
0
 

Author Closing Comment

by:alam747
ID: 38776681
Thanks a lot..
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

707 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

14 Experts available now in Live!

Get 1:1 Help Now