Solved

How to delete specific sheet from a excel workbook from access

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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38773191
;-)
0
 

Author Closing Comment

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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Outlook Free & Paid Tools
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

770 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