Create excel file and enter some data save it
view plainprint?
1. '###############################################
2. 'Create excel file and enter some data save it
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Add New Workbook
12. Set workbooks=[Link]()
13.
14. 'Set the value in First row first column
15. [Link](1,1).value="testing"
16.
17. 'Save Work Book
18. [Link]"D:\[Link]"
19.
20. 'Close Work Book
21. [Link]
22.
23. 'Quit from Excel Application
24. [Link]
25.
26. 'Release Variables
27. Set workbooks=Nothing
28. Set excel=Nothing
Reading Values from a Specific excel Sheet
view plainprint?
1. '###############################################
2. ' Reading Values from a Specific excel Sheet
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open the Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Get the Control on Specific Sheet
15. Set worksheet1=[Link]("Sheet1")
16.
17. ' Display the Values
18. Msgbox [Link](1,1).value
19.
20. 'Close Work Book
21. [Link]
22.
23. 'Quit from Excel Application
24. [Link]
25.
26. 'Release Variables
27. Set worksheet1=Nothing
28. Set workbook=Nothing
29. Set excel=Nothing
Deleting Rows from Excel Sheet
view plainprint?
1. '###############################################
2. ' Deleting Rows from Excel Sheet
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open the Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Get the Control on Specific Sheet
15. Set worksheet1=[Link]("Sheet1")
16.
17. 'Delete Row1
18. [Link]("1:1").delete
19.
20. 'Save Excel
21. [Link]("D:\[Link]")
22.
23. 'Close Work Book
24. [Link]
25.
26. 'Quit from Excel Application
27. [Link]
28.
29. 'Release Variables
30. Set worksheet1=Nothing
31. Set workbook=Nothing
32. Set excel=Nothing
Add and Delete ExcelSheet
view plainprint?
1. '###############################################
2. ' Add and Delete ExcelSheet
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open Existing Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Add New Sheet
15. Set newsheet=[Link]
16.
17. 'Assign a Name
18. [Link]="raj"
19.
20. 'Delete Sheet
21. Set delsheet=[Link]("raj")
22. [Link]
23.
24. 'Close Work Book
25. [Link]
26.
27. 'Quit from Excel Application
28. [Link]
29.
30. 'Release Variables
31. Set newsheet=Nothing
32. Set delsheet=Nothing
33. Set workbook=Nothing
34. Set excel=Nothing
Copy an Excel Sheet of one Excel File to another Excel File
view plainprint?
1. '###############################################
2. ' Copy an Excel Sheet of one Excel File to another Excel File
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open First Excel File
12. Set workbook1=[Link]("D:\[Link]")
13.
14. 'Open Second Excel File
15. Set workbook2=[Link]("D:\[Link]")
16.
17. 'Copy data from first excel file sheet
18. [Link]("raj").[Link]
19.
20. 'Paste Data to Second Excel File Sheet
21. [Link]("Sheet1").pastespecial
22.
23. 'Save Workbooks
24. [Link]
25. [Link]
26.
27. 'Close Workbooks
28. [Link]
29. [Link]
30.
31. 'Quit from Excel Application
32. [Link]
33.
34. 'Release Variables
35. Set workbook1=Nothing
36. Set workbook2=Nothing
37. Set excel=Nothing
Comapre Two Excel Sheets Cell By Cell for a specific Range
view plainprint?
1. '###############################################
2. ' Comapre Two Excel Sheets Cell By Cell for a specific Range
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Get Control on First Sheet
15. Set sheet1=[Link]("Sheet1")
16.
17. 'Get Control on Second Sheet
18. Set sheet2=[Link]("Sheet2")
19.
20. 'Give the specific range for Comparision
21. CompareRangeStartRow=1
22. NoofRows2Compare=4
23. CompareRangeStartColumn=1
24. NoofColumns2Compare=4
25.
26. 'Loop through Rows
27. For r=CompareRangeStartRow to(CompareRangeStartRow+
(NoofRows2Compare-1))
28.
29. 'Loop through columns
30. For c=CompareRangeStartColumn to(CompareRangeStartColumn+
(NoofColumns2Compare-1))
31.
32. 'Get Value from the First Sheet
33. value1=Trim([Link](r,c))
34. 'Get Value from the Second Sheet
35. value2=Trim([Link](r,c))
36.
37. 'Compare Values
38. If value1<>value2 Then
39.
40. ' If Values are not matched make the text with Red color
41. [Link](r,c).[Link]=vbred
42.
43. End If
44.
45. Next
46.
47. Next
48.
49. 'Save workbook
50. [Link]
51.
52. 'Close Work Book
53. [Link]
54.
55. 'Quit from Excel Application
56. [Link]
57.
58. 'Release Variables
59. Set sheet1=Nothing
60. Set sheet2=Nothing
61. Set workbook=Nothing
62. Set excel=Nothing
Reading complete data from excel file
view plainprint?
1. '###############################################
2. ' Reading complete data from excel file
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Get Control on Sheet
15. Set worksheet=[Link]("raj")
16.
17. 'Get the count of used columns
18. ColumnCount=[Link]
19.
20. 'Get the count of used Rows
21. RowCount=[Link]
22.
23. 'Get the Starting used Row and column
24. top=[Link]
25. lft=[Link]
26.
27. 'Get cell object to get the values cell by cell
28. Set cells=[Link]
29.
30. 'Loop through Rows
31. For row=top to (RowCount-1)
32. rdata=""
33. 'Loop through Columns
34. For col=lft to ColumnCount-1
35. 'Get Cell Value
36. word=cells(row,col).value
37.
38. 'concatenate all row cell values into one variable
39. rdata=rdata&vbtab&word
40. Next
41.
42. 'Print complete Row Cell Values
43. print rdata
44. Next
45.
46. 'Close Work Book
47. [Link]
48.
49. 'Quit from Excel Application
50. [Link]
51.
52. 'Release Variables
53. Set worksheet=Nothing
54. Set workbook=Nothing
55. Set excel=Nothing
Read complete data from an Excel Sheet content
view plainprint?
1. '###############################################
2. ' Read complete data from an Excel Sheet content
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Open Excel File
12. Set workbook=[Link]("D:\[Link]")
13.
14. 'Get Control on Sheet
15. Set worksheet=[Link]("Sheet1")
16.
17. 'Get Used Row and Column Count
18. rc=[Link]
19. cc=[Link]
20.
21. 'Loop through Rows
22. For Row=1 to rc
23. 'Loop through Columns
24. For Column=1 to cc
25. 'Get Cell Data
26. RowData=RowData&[Link](Row,Column)&vbtab
27. Next
28. RowData=RowData&vbcrlf
29. Next
30.
31. 'Display complete Data
32. msgbox RowData
33.
34. 'Close Work Book
35. [Link]
36.
37. 'Quit from Excel Application
38. [Link]
39.
40. 'Release Variables
41. Set worksheet=Nothing
42. Set workbook=Nothing
43. Set excel=Nothing
Assign Colours to Excel Sheet Cells, Rows
view plainprint?
1. '###############################################
2. ' Assign Colours to Excel Sheet Cells, Rows
3. '###############################################
4.
5. 'Create Excel Object
6. Set excel=createobject("[Link]")
7.
8. 'Make it Visible
9. [Link]=True
10.
11. 'Add a New work book
12. Set workbook=[Link]()
13.
14. 'Get the Excel Sheet
15. Set worksheet=[Link](1)
16.
17. 'Coloring Excell Sheet Rows
18. Set objrange=[Link]
19. [Link]=37
20.
21. 'Coloring Excell Sheet Cell
22. [Link](2,1).[Link]=36
23.
24. 'Save Excel
25. [Link]("D:\[Link]")
26.
27. 'Close Work Book
28. [Link]
29.
30. 'Quit from Excel Application
31. [Link]
32.
33. 'Release Variables
34. Set objrange=Nothing
35. Set worksheet=Nothing
36. Set workbook=Nothing
37. Set excel=Nothing