在VB中引用Microsoft Excel 11.0 Object Library,其中11.0是Office的版本号,根据你机器上装的Excel版本不同而不同.
使用代码控制
下面代码是将sheet1的内容插入到第sheet2,并且每行上加一行,第一列名叫"标题",其他行为空,供你研究,不多做解释了,当你明白怎么回事,绝对可以完成你要的功能,我给的只是一个试例,请自己完成你要的代码
Dim e As New Excel.Application
Dim s As Excel.Worksheet
Dim s2 As Excel.Worksheet
e.Workbooks.Open "e:\book1.xls"
Set s = e.Sheets(1)
Set s2 = e.Sheets(2)
For i = 1 To s.Rows.Count
If s.Rows(i).Cells(1) <> "" Then
For j = 1 To s.Rows(i).Cells.Count
If s.Rows(i).Cells(j) = "" Then
Exit For
Else
s2.Rows(i * 2 - 1).Cells(1) = "标题"
s2.Rows(i * 2).Cells(j) = s.Rows(i).Cells(j)
End If
Next
Else
Exit For
End If
Next i
e.SaveWorkspace
e.Workbooks.Close