Step 1) Lets Create these functions First(These functions are independent we can use these functions for any application)
Function No1:-getRowCount
Function getRowCount(filePath,sheetName)
' all the cells for all the cols are empty
' know total cols in the sheet
Dim cols,isRowPresent,rows,isLastRow
cols = getColumnCount(filePath,sheetName)
rows=1 ' assuming there is one row
isRowPresent = true
isLastRow= false
While isRowPresent
' check to see if all the cells are empty or not
Dim colNum
For colNum=1 to cols
If readData(filePath,sheetName,rows,colNum) <> "" Then
' this is not the last row
rows=rows+1
Exit for
End If
' if you have just read the last cell
If colNum = cols Then
' this is the last row
isLastRow = true
Exit for
End If
Next
' check if its the last row
If isLastRow Then
isRowPresent=false
End If
Wend
getRowCount= (rows-2)
End Function
Function No2:- getColumnCount
'return total cols in a sheet
Function getColumnCount(filePath,sheetName)
Dim colCount
colCount=0 ' assume no cols
While trim(readData(filePath,sheetName,1,(colCount+1))) <> ""
colCount = colCount+1
Wend
getColumnCount= colCount
End Function
Function No3 :readData
Function readData(filePath, sheetName, row,col)
Set objXls = createobject("Excel.application") '' microsoft xl
objXls.Visible= false
objXls.DisplayAlerts=false
' exit the function if file is not present
If NOT isFilePresent(filePath) Then
msgbox "FILE NOT PRESENT " & filePath
Exit function
End If
Set myXls = objXls.Workbooks.Open (filePath)
Set sheet = myXls.Sheets(sheetName)
readData = sheet.cells(row,col).value
' close everything
myXls.Close
objXls.Quit
' destroy object
Set objXls=nothing
Set myXls=nothing
Set sheet=nothing
End Function
Function No5: isFilePresent
' function returns true if file is present and false if not present
Function isFilePresent(filePath)
Set fso = createobject("Scripting.FileSystemObject")
If fso.FileExists(filePath) Then
isFilePresent = true
else
isFilePresent=false
End If
' destroy object
Set fso= nothing
End Function
Function No1:-getRowCount
Function getRowCount(filePath,sheetName)
' all the cells for all the cols are empty
' know total cols in the sheet
Dim cols,isRowPresent,rows,isLastRow
cols = getColumnCount(filePath,sheetName)
rows=1 ' assuming there is one row
isRowPresent = true
isLastRow= false
While isRowPresent
' check to see if all the cells are empty or not
Dim colNum
For colNum=1 to cols
If readData(filePath,sheetName,rows,colNum) <> "" Then
' this is not the last row
rows=rows+1
Exit for
End If
' if you have just read the last cell
If colNum = cols Then
' this is the last row
isLastRow = true
Exit for
End If
Next
' check if its the last row
If isLastRow Then
isRowPresent=false
End If
Wend
getRowCount= (rows-2)
End Function
Function No2:- getColumnCount
'return total cols in a sheet
Function getColumnCount(filePath,sheetName)
Dim colCount
colCount=0 ' assume no cols
While trim(readData(filePath,sheetName,1,(colCount+1))) <> ""
colCount = colCount+1
Wend
getColumnCount= colCount
End Function
Function No3 :readData
Function readData(filePath, sheetName, row,col)
Set objXls = createobject("Excel.application") '' microsoft xl
objXls.Visible= false
objXls.DisplayAlerts=false
' exit the function if file is not present
If NOT isFilePresent(filePath) Then
msgbox "FILE NOT PRESENT " & filePath
Exit function
End If
Set myXls = objXls.Workbooks.Open (filePath)
Set sheet = myXls.Sheets(sheetName)
readData = sheet.cells(row,col).value
' close everything
myXls.Close
objXls.Quit
' destroy object
Set objXls=nothing
Set myXls=nothing
Set sheet=nothing
End Function
Function No4:closeAllBrowsers
Function closeAllBrowsers
Dim desc,allBrowsers,i
Set desc = description.Create
desc("micclass").value="Browser"
Set allBrowsers = desktop.ChildObjects(desc)
For i=0 to allBrowsers.count-1
Browser("creationtime:="&i).close
Next
Set desc=Nothing
Set allBrowsers =Nothing
End Function
Function No5: isFilePresent
' function returns true if file is present and false if not present
Function isFilePresent(filePath)
Set fso = createobject("Scripting.FileSystemObject")
If fso.FileExists(filePath) Then
isFilePresent = true
else
isFilePresent=false
End If
' destroy object
Set fso= nothing
End Function
Step 2)Add these functions into your Action
Step 3)And follows The script
Dim Login,Pwd,cnt
cnt=getRowCount("c:\abc.xls","Login")
'c:\abc.xls=path of your xls file
'Login=sheet name
msgbox cnt
For i=2 to cnt+1
closeAllBrowsers
Systemutil.Run "http://www.salesforce.com","firefox"
set a=Browser("title:=.*").Page("title:=.*")
'a.Sync
a.link("name:=Login").Click
Login=readData ("c:\abc.xls","Login",i,1)
'msgbox Login
pwd=readData ("c:\abc.xls","Login",i,2)
'msgbox pwd
a.webedit("name:=username").Set Login
a.webedit("name:=pw").Set Pwd
a.webbutton("name:=Log in to Salesforce").Click
a.Sync
next
*******************************************************
No comments:
Post a Comment