标题:请看我的ACCESS数据转换为EXCEL的代码哪里错了
只看楼主
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
结帖率:84.62%
 问题点数:0 回复次数:6 
请看我的ACCESS数据转换为EXCEL的代码哪里错了

请看我的ACCESS数据转换为EXCEL的代码哪里错了?

怎么点击“转换”按钮时,怎么转换不起来呢?

我是转贴别人的代码,稍作修改而成!

“转换”按钮代码如下:

appdisk = Trim(App.Path)
If Right(appdisk, 1) <> "\" Then appdisk = appdisk & "\"
Dim lRow As Long
Dim sXLSPath As String
Dim MyExcel As New Excel.Application
Dim MyBook As Excel.Workbook
Dim MySheet As Excel.Worksheet
Dim s As String
Dim i As Integer
Dim j As Integer
Screen.MousePointer = 11
sXLSPath = appdisk & "gcjs.xls"
Open sXLSPath For Output As #1
Close #1
Set MyExcel = CreateObject("excel.application")
Set MyBook = MyExcel.Workbooks.Open(sXLSPath)
Set MySheet = MyExcel.ActiveSheet
MySheet.Range("A1:O1").Select
With MyExcel.Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With

MySheet.Columns("A:C").NumberFormat = "0_ "
MySheet.Columns(1).ColumnWidth = 5
。。。
。。。
MySheet.Cells(1, 1) = "K(常数)"
MySheet.Cells(2, 1) = 100 。。。
。。。
For i = 2 To rst.Fields.Count
For j = 2 To rst.RecordCount
MySheet.Cells(j, i).Value = rst.Fields(i - 1).Value
Next j
Next i

具体请看附件!

谢谢!

MVKCMBSY.rar (24.85 KB) 请看我的ACCESS数据转换为EXCEL的代码哪里错了


搜索更多相关主题的帖子: EXCEL ACCESS 数据 代码 
2007-07-10 23:53
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
得分:0 

去掉不必要的引用就不会报错

同时 记得处理完后 关闭打开的 Excel 文件

[此贴子已经被作者于2007-7-11 0:36:55编辑过]


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-07-11 00:35
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
能具体详细点么?
2007-07-11 15:20
qlong0728
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:272
专家分:0
注 册:2007-6-15
得分:0 

建议改成
Dim lRow As Long
Dim sXLSPath As String
Dim MyExcel As New Excel.Application
Dim MyBook As Excel.Workbook
Dim MySheet As Excel.Worksheet
Dim s As String
Dim i As Integer
Dim j As Integer
Screen.MousePointer = 11
Set MyExcel = CreateObject("excel.application")
Set MyBook = MyExcel.Workbooks.Add
Set MySheet = MyExcel.Worksheets(1)
MySheet.Range("A1:O1").Select
With MyExcel.Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With

MyExcel.Visible = True


MySheet.Columns("A:C").NumberFormat = "0_ "
MySheet.Columns(1).ColumnWidth = 5
MySheet.Columns(2).ColumnWidth = 10
MySheet.Columns(3).ColumnWidth = 10
MySheet.Columns(4).ColumnWidth = 10
MySheet.Columns(5).ColumnWidth = 10
MySheet.Columns(6).ColumnWidth = 10
MySheet.Columns(7).ColumnWidth = 10
MySheet.Columns(8).ColumnWidth = 10
MySheet.Columns(9).ColumnWidth = 10
MySheet.Cells(1, 1) = "K(常数)"
MySheet.Cells(2, 1) = 100

MySheet.Cells(1, 2) = "度"
MySheet.Cells(1, 3) = "分"
MySheet.Cells(1, 4) = "秒"
MySheet.Cells(1, 5) = "上丝"
MySheet.Cells(1, 6) = "中丝"
MySheet.Cells(1, 7) = "下丝"
MySheet.Cells(1, 8) = "测距"
For i = 2 To rst.Fields.Count
For j = 2 To rst.RecordCount
MySheet.Cells(j, i).Value = rst.Fields(i - 1).Value
Next j
Next i
Screen.MousePointer = 0

如果你要用不显示的转换,在转换完后加一条语句关闭EXCEL表就可以了


程序人员写程序,又拿程序换酒钱。 奔驰宝马贵者趣,公交自行程序员。 不见满街漂亮妹,哪个归得程序员。
2007-07-11 16:34
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
MDB里的数据怎么转换为XLS的却全是当前所输入的数据?前面的几个数据全部被刚刚输入的数据所替代了?
尽管数据个数是正确的!
2007-07-11 22:30
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

请看我刚刚修改的“转换”(Command4)控件的代码如下:

Private Sub Command4_Click()
appdisk = Trim(App.Path)
If Right(appdisk, 1) <> "\" Then appdisk = appdisk & "\"
Dim lRow As Long
Dim sXLSPath As String
Dim MyExcel As New Excel.Application
Dim MyBook As Excel.Workbook
Dim MySheet As Excel.Worksheet
Dim s As String
Dim i As Integer
Dim j As Integer
Screen.MousePointer = 11
sXLSPath = appdisk & "gcjs.xls"

Set MyExcel = CreateObject("excel.application")
Set MyBook = MyExcel.Workbooks.Open(sXLSPath)
Set MySheet = MyExcel.ActiveSheet
MySheet.Range("A1:O1").Select
With MyExcel.Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
MyExcel.Visible = True


MySheet.Columns("A:C").NumberFormat = "0_ "
MySheet.Columns(1).ColumnWidth = 5
MySheet.Columns(2).ColumnWidth = 10
MySheet.Columns(3).ColumnWidth = 10
MySheet.Columns(4).ColumnWidth = 10
MySheet.Columns(5).ColumnWidth = 10
MySheet.Columns(6).ColumnWidth = 10
MySheet.Columns(7).ColumnWidth = 10
MySheet.Columns(8).ColumnWidth = 10
MySheet.Columns(9).ColumnWidth = 10
MySheet.Cells(1, 1) = "K(常数)"
MySheet.Cells(2, 1) = 100

MySheet.Cells(1, 2) = "度"
MySheet.Cells(1, 3) = "分"
MySheet.Cells(1, 4) = "秒"
MySheet.Cells(1, 5) = "上丝"
MySheet.Cells(1, 6) = "中丝"
MySheet.Cells(1, 7) = "下丝"
MySheet.Cells(1, 8) = "测距"
For i = 2 To rst.Fields.Count
For j = 2 To rst.RecordCount
MySheet.Cells(j, i).Value = rst.Fields(i - 1).Value
Next j
Next i
Screen.MousePointer = 0

End Sub

2007-07-11 22:33
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
得分:0 

Repeat  Life=Study;Until (death);
2007-07-11 23:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-154491-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.097679 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved