主题:使用VB6.0怎样对EXCEL进行操作?
peikexin
[专家分:0] 发布于 2008-09-04 14:26:00
我之前编写了一段宏来处理excel的数据,现在需要用VB来取代,命令是不是都不一样了啊?
有没有相关的教程或者链接?谢谢大侠[em1]
回复列表 (共5个回复)
沙发
merry05 [专家分:8920] 发布于 2008-09-04 17:52:00
只能说很类似
板凳
joforn [专家分:1460] 发布于 2008-09-04 17:59:00
基本上是一样的。
3 楼
peikexin [专家分:0] 发布于 2008-09-05 09:28:00
那么可有相关的教程或者文章呢?谢谢了
4 楼
shibaolingyn [专家分:510] 发布于 2008-09-07 21:33:00
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
If VarType(oExcel) > vbBoolean Then
MsgBox "Microsoft EXCEL 没有安装或损坏!或因为内存不够不能调用编辑!", vbInformation
Exit Sub
End If
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oExcel.Application.Caption = "云南省区域气象观测站数据 当前编辑" '指定标题栏名称
'向 Excel中传输数据
ProgressBar1.Visible = True
ProgressBar1.value = 0
For I = 1 To MyCount 'MyCount是数组textline的下标
oSheet.Range("A" & I).value = textline(1, I - 1)
oSheet.Range("B" & I).value = textline(2, I - 1)
oSheet.Range("C" & I).value = textline(3, I - 1)
oSheet.Range("D" & I).value = textline(4, I - 1)
oSheet.Range("E" & I).value = textline(5, I - 1)
oSheet.Range("F" & I).value = textline(6, I - 1)
oSheet.Range("G" & I).value = textline(7, I - 1)
oSheet.Range("H" & I).value = textline(8, I - 1)
ProgressBar1.value = I / MyCount * 100
Next
oSheet.Rows("1:1").Insert
oSheet.Range("A1").value = "站名"
oSheet.Range("B1").value = "区站号"
oSheet.Range("C1").value = "经度"
oSheet.Range("D1").value = "纬度"
oSheet.Range("E1").value = "雨量"
oSheet.Range("F1").value = "(平均)温度"
oSheet.Range("G1").value = "测站海拔"
oSheet.Range("H1").value = "收报率"
oSheet.Rows("1:1").Insert
oSheet.Range("A1").value = Mid(timestring, 6) & " 资料统计"
oSheet.Columns("E:G").NumberFormatLocal = "0.0_ "
oSheet.Range("A1:H1").merge
oSheet.Range("A1").horizontalAlignment = 3
oSheet.Range("A1").verticalAlignment = 2
With oSheet.cells.Borders '边框设置
.LineStyle = xlBorderLineStyleContinuous
.ColorIndex = 1
End With
oSheet.Range("A" & I + 2 & ":H" & I + 2).merge
oSheet.Range("A" & I + 2).value = " 制表人 : 校对人: 制作单位:" & " 气象局"
With oSheet.PageSetup
.Orientation = 1 'xlLandscape
.LeftMargin = 45
.RightMargin = 45
.FirstPageNumber = 1 'xlAutomatic
.CenterHorizontally = True
'.CenterVertically = True
'.TopMargin = 55
.BottomMargin = 45
' .HeaderMargin = Application.InchesToPoints(0.511811023622047)
' .FooterMargin = Application.InchesToPoints(0.511811023622047)
.CenterFooter = "第&P页"
.LeftFooter = "云南省自动气象站资料"
.RightFooter = " 共&N页 生成时间:&D &T"
End With
oExcel.Visible = True '可以使用 xlApp 访问 Microsoft Excel 的其它对象。
5 楼
peikexin [专家分:0] 发布于 2008-09-08 10:17:00
[quote]Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
If VarType(oExcel) > vbBoolean Then
MsgBox "Microsoft EXCEL 没有安装或损坏!或因为内存不够不能调用编辑!", vbInformation
Exit Sub
End If
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oExcel.Application.Caption = "云南省区域气象观测站数据 当前编辑" '指定标题栏名称
'向 Excel中传输数据
ProgressBar1.Visible = True
ProgressBar1.value = 0
For I = 1 To MyCount 'MyCount是数组textline的下标
oSheet.Range("A" & I).value = textline(1, I - 1)
oSheet.Range("B" & I).value = textline(2, I - 1)
oSheet.Range("C" & I).value = textline(3, I - 1)
oSheet.Range("D" & I).value = textline(4, I - 1)
oSheet.Range("E" & I).value = textline(5, I - 1)
oSheet.Range("F" & I).value = textline(6, I - 1)
oSheet.Range("G" & I).value = textline(7, I - 1)
oSheet.Range("H" & I).value = textline(8, I - 1)
ProgressBar1.value = I / MyCount * 100
Next
oSheet.Rows("1:1").Insert
oSheet.Range("A1").value = "站名"
oSheet.Range("B1").value = "区站号"
oSheet.Range("C1").value = "经度"
oSheet.Range("D1").value = "纬度"
oSheet.Range("E1").value = "雨量"
oSheet.Range("F1").value = "(平均)温度"
oSheet.Range("G1").value = "测站海拔"
oSheet.Range("H1").value = "收报率"
oSheet.Rows("1:1").Insert
oSheet.Range("A1").value = Mid(timestring, 6) & " 资料统计"
oSheet.Columns("E:G").NumberFormatLocal = "0.0_ "
oSheet.Range("A1:H1").merge
oSheet.Range("A1").horizontalAlignment = 3
oSheet.Range("A1").verticalAlignment = 2
With oSheet.cells.Borders '边框设置
.LineStyle = xlBorderLineStyleContinuous
.ColorIndex = 1
End With
oSheet.Range("A" & I + 2 & ":H" & I + 2).merge
oSheet.Range("A" & I + 2).value = " 制表人 : 校对人: 制作单位:" & " 气象局"
With oSheet.PageSetup
.Orientation = 1 'xlLandscape
.LeftMargin = 45
.RightMargin = 45
.FirstPageNumber = 1 'xlAutomatic
.CenterHorizontally = True
'.CenterVertically = True
'.TopMargin = 55
.BottomMargin = 45
' .HeaderMargin = Application.InchesToPoints(0.511811023622047)
' .FooterMargin = Application.InchesToPoints(0.511811023622047)
.CenterFooter = "第&P页"
.LeftFooter = "云南省自动气象站资料"
.RightFooter = " 共&N页 生成时间:&D &T"
End With
oExcel.Visible = True '可以使用 xlApp 访问 Microsoft Excel 的其它对象。
[/quote]
ProgressBar.Visible = True
到这句的时候出现错误424
我来回复