Wapug
Registered User.
- Local time
- Today, 06:19
- Joined
- Apr 14, 2017
- Messages
- 51
I am trying to perform a variety of things from a VBA module in Access to open an excel workbook and delete a sheet and it doesn't seem to be working. I am using Access and Excel 2013, and am trying to delete a sheet in a workbook. The module runs and gives me the process complete but when I open the spreadsheet the worksheet labeled INVENTORY, is still there. What am I doing wrong here?
Private Sub Command0_Click()
Dim xl As Object
Dim wb As Excel.Workbook
Dim Sht As Excel.Worksheet
Set xl = CreateObject("excel.Application")
Set wb = xl.Workbooks.Open("C:\Users\bacon\Desktop\test1.xlsx")
For Each Sht In wb.Worksheets
If Sht.Name = "INVENTORY" Then
wb.Worksheets("INVENTORY").Select
xl.ActiveSheet.Delete
End If
Next Sht
wb.Save
wb.Close
xl.Quit
MsgBox "Process complete!"
End Sub
:banghead:
Private Sub Command0_Click()
Dim xl As Object
Dim wb As Excel.Workbook
Dim Sht As Excel.Worksheet
Set xl = CreateObject("excel.Application")
Set wb = xl.Workbooks.Open("C:\Users\bacon\Desktop\test1.xlsx")
For Each Sht In wb.Worksheets
If Sht.Name = "INVENTORY" Then
wb.Worksheets("INVENTORY").Select
xl.ActiveSheet.Delete
End If
Next Sht
wb.Save
wb.Close
xl.Quit
MsgBox "Process complete!"
End Sub
:banghead: