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
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
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 06:44 AM.
Hi Deepa
how to get sheet count of external excel sheet without import the excel sheet?
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,
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
What is the difference between Workbook.Worksheets and Workbook.Sheets?