Results 1 to 6 of 6

Thread: How to get sheet count of an excel workbook in QTP?

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Answers
    1

    How to get sheet count of an excel workbook in QTP?

    I want to get the sheet count of an excel workbook in QTP.

    Let me know the different methods of doing it.

    Thanks in advance


  2. #2
    Expert Member
    Join Date
    Apr 2008
    Answers
    1,859

    Re: How to get sheet count of an excel workbook in QTP?

    hai friend,


    Datatable.ImportSheet "C:\Documents and settings\specify your user name here\Desktop\test.xls",1,1
    sheetcount = DataTable.GetSheetCount
    Msgbox sheetcount

    To get sheet count what I have done here is I have imported an excel sheet named(test.xls) and then counted the number of used sheet in that excel workbook.

    Note: This method is used to find the total number of sheets in the run-time Data Table

    Thanks
    Deepa

    Last edited by deepasree; 04-28-2009 at 05:44 AM.

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Answers
    27

    Arrow Re: How to get sheet count of an excel workbook in QTP?

    Hi Deepa

    how to get sheet count of external excel sheet without import the excel sheet?


  4. #4
    Expert Member
    Join Date
    Oct 2007
    Answers
    375

    Re: How to get sheet count of an excel workbook in QTP?

    Hi,

    Try the below code which uses the method of creating an Object of Excel -

    Dim objExcel
    Dim sPath

    Set sPath = "<>"

    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbooks = objExcel.Workbooks.Open(sPath)

    nWorkSheetCount = objExcel.Worksheets.count

    msgbox "There are a total of" & nWorkSheetCount & "worksheets"

    Cheers,


  5. #5
    Expert Member
    Join Date
    Apr 2008
    Answers
    1,859

    Re: How to get sheet count of an excel workbook in QTP?

    Hi friend,

    The code should be as follows

    Dim objExcel
    Dim sPath
    sPath="C:\New Folder\Sample"
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbooks = objExcel.Workbooks.Open(sPath)
    nWorkSheetCount = objExcel.Worksheets.count
    msgbox "There are a total of" &nWorkSheetCount &"worksheets"

    Method 2

    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open _
    ("C:\New Folder\Sample")
    objExcel.visible="True"
    SheetCount = objExcel.Worksheets.count
    msgbox SheetCount

    Thanks,
    Deepa

    Arise Awake And Stop Not Till The Goal Is Reached

  6. #6
    Junior Member
    Join Date
    Aug 2013
    Answers
    1

    Re: How to get sheet count of an excel workbook in QTP?

    What is the difference between Workbook.Worksheets and Workbook.Sheets?


  7.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact