Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15900

Delete Excel Sheets With Name Criteria

$
0
0
Dear All

I have a code to delete excel sheets having a common Criteria in their Names Like T10, T12, T16 and so on
I want the code to delete these sheets, the code is working on VBA but it does not on vb.net ??

My Code is
g
Code:

Private Sub DeleteTSheets()
        Dim xl As New Excel.Application
        Dim wb As Excel.Workbook
        Dim ws as Excel.Worksheet
        wb = xl.Workbooks.Open("C:\Patches\Main_Final.xlsm")
        For Each ws in wb.sheets
          If InStr(1, wb.Sheets(i).Name, "T") Then
              If len(ws.name)=3 then
                  ws.delete()
              End If
          End If
        Next
      End Sub

So, What is wrong exactly?

Thanks, Regards

Moheb Labib

Viewing all articles
Browse latest Browse all 15900


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>