Solved

How to delete specific sheet from a excel workbook from access

Posted on 2013-01-13
4
486 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

930 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

9 Experts available now in Live!

Get 1:1 Help Now