Google

Sunday, June 22, 2008

i-TimeTabler Notes: Merging Excel Cells and Setting Cell Size

Add project references to Excel:



This is the code for merging cells in Excel using VB6:



The advantage of adding the references is that you will get the
Intellisense auto-completion when coding. But not good
for distributing program, since it is early binding.

You can set cell size:

Private Sub cmdMergeCells_Click()
xlApp.Application.Visible = True
xlSheet.Cells(1, 3).Value = "AB CD"
With xlSheet
.Range(xlSheet.Cells(1, 3), xlSheet.Cells(1, 4)).MergeCells = True
'.Range("C1:D1").MergeCells = True
.Range("C1:D1").Font.Bold = True
.Range("C1:D1").Font.ColorIndex = 50
.Range("C1:D1").ColumnWidth = 6
.Range("C1:D1").RowHeight = 35
.Range("C1:D1").HorizontalAlignment = xlDistributed
.Range("C1:D1").VerticalAlignment = xlDistributed
End With
End Sub



ToDo:
Late Binding example