Solved

How to delete specific sheet from a excel workbook from access

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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