locked
check the Existence worksheet in excel RRS feed

  • Question

  • User-1169942342 posted

    Hi all,

    i would like to chack the existence worksheet in the excel file i upload. how to check it, below is my coding in vb.net:

     

      Dim xlsApp As Excel.Application
            Dim wbkPA As Excel.Workbook
            Dim wshPA As Excel.Worksheet
    
     xlsApp = New Excel.Application
                xlsApp.Visible = False
                xlsApp.DisplayAlerts = False
                Try
                    wbkPA = xlsApp.Workbooks.Open(viewExcelPath)
                                      if    wbkPA.Worksheets.Item("sheet 1").exist = true then    'HOW TO CHECK THE WORKSHEET EXIST OR NOT?                                     wshPA = wbkPA.Worksheets.Item("sheet 1")
                   end if

     

    appreciate to get your reply soon.

    thank you.

    Thursday, July 7, 2011 9:16 AM

Answers

  • User1835401063 posted

    If you want to write your code in VBA (press Alt+F11), then this is the code:

    Sub a()
    Dim i As Integer
    Dim s As Worksheet


    For i = 1 To Sheets.Count
    Set s = ThisWorkbook.Sheets(i)
    Debug.Print s.Name
    Next

    End Sub
    
    
    I think you can easily change this VBA code to vb.net version. Take care that default start of list index in VBA is 1 bt in .net it startes from 0.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 7, 2011 9:53 AM

All replies

  • User1835401063 posted

    If you want to write your code in VBA (press Alt+F11), then this is the code:

    Sub a()
    Dim i As Integer
    Dim s As Worksheet


    For i = 1 To Sheets.Count
    Set s = ThisWorkbook.Sheets(i)
    Debug.Print s.Name
    Next

    End Sub
    
    
    I think you can easily change this VBA code to vb.net version. Take care that default start of list index in VBA is 1 bt in .net it startes from 0.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 7, 2011 9:53 AM
  • User3866881 posted

    i would like to chack the existence worksheet in the excel file i upload.

    Hello:)

    In my mind I think you can just send your request here:http://social.msdn.microsoft.com/Forums/en-us/vsto/threads, which supports VS Tools for Office Programming.

    Thx again.

    Friday, July 8, 2011 10:50 PM