Naa koy program na makabuhat ani. Unya nibuhat sad ko ug tut about ani. Makita ni nimo sa ako blog, d lang nako ipost ang link.
You have to have a reference of ms excel on vb6. Do this by:
1. Open Visual Basic 6.0.
2. Add a new project. ( FILE > NEW)
3. Select STANDARD EXE > click OK.
4. Add a reference, Go to PROJECT > REFERENCE.
5. On the Pop-up window, Scroll down and look for MICROSOFT EXCEL 11.0 Object Library. In my case, I'm using Excel 2003 that is why it is 11.0, could be another version depending on what you have on your computer.
That's it! you now have a reference to excel. Below are the codes you can use:
Dim objExcel As New Excel.Application
Set objExcel = New Excel.Application
First you have to declare a variable(above) to ensure that you can use the codes below:
Sheet Settings:
objExcel.Workbooks.Add
objExcel.Cells.Select
With objExcel.Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 8
.Strikethrough = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
To add text on a cell:
objExcel.Cells(Row, Col) = "Your Text Here"
Merge Cells
objExcel.Range().MergeCells = True
'Ex:.Range("B2:G2").MergeCells = True
Center Cell Data
objExcel.Range().HorizontalAlignment = Excel.Constants.xlCenter
'Ex: objExcel.Range("B2:G2").HorizontalAlignment = Excel.Constants.xlCenter
Column Width
objExcel.Range("A1:A1").ColumnWidth = 5
Cell Backcolor
objExcel.Cells(Row,Coli).Interior.ColorIndex = 15
Adding Borders to a cell
Public Sub CellBorder(Row As Integer, Col As Integer, Side As XlBordersIndex, Style As XlLineStyle, Weight As XlBorderWeight, Color As Long)
With objExcel.Cells(Row, Col).Borders(Side)
.LineStyle = Style
.Weight = Weight
.ColorIndex = Color
End With
End Sub
To Password protect Excel file:
objExcel.Worksheets("Sheet1").Protect Password:=
To display Excel
objExcel.Visible = True