Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to delete specific sheet from a excel workbook from access

Posted on 2013-01-13
4
Medium Priority
?
506 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 2000 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 93

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

972 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