| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 566 人关注过本帖
标题:代码出错了``````````
只看楼主 加入收藏
baiqie
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2007-1-19
收藏
 问题点数:0 回复次数:6 
代码出错了``````````

Private Sub Form_Load()
Dim objxl As New Excel.Application
Dim objxlbook As Excel.Workbook
Dim objxlsheet As Excel.Worksheet
Dim objxlchart As ChartObject
Dim strfile As String
Dim db As Database
Dim rs As String
Dim intloop As Integer
End Sub

Private Sub Recordsource_Click()
Set objxlbook = objxl.Workbooks.Add
Set objxlsheet = objxlbook.Worksheets("sheet1")
strfiloe = "C:\Report.xls"
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset(Me.Reports)
intloop = 1
With objxlsheet
.Cells(intloop, 1) = rs.Fields(0).Name
.Cells(intloop, 2) = rs.Fields(1).Name
intloop = intloop + 1
Do
.Cells(intloop, 1) = rs.Fields(0)
.Cells(intloop, 2) = rs.Fields(1)
intloop = intloop + 1
rs.MoveNext
Loop Until rs.EOF
Set objxlchart = .ChartObjects.Add(156, 0, 0, 300)
objxlchart.Activate
With objxlchart.Chart
If Me.ChartTypeOption.Value = 1 Then
.ChartType = xl3DPieExploded
Else
.ChartType = xl3DColumn
End If
.ChartArea.Border.LineStyle = xlNone
.SeriesCollection.Add Source:=objxlbook.Sheets("sheet1").Range("A1:B" & intloop - 1)
.HasTitle = True
.ChartTitle.Text = Me.Reports
.Legend.Position = xlLegendPositionRight
.ApplyDataLabels xlDataLabelsShowValue
End With
.Cells(1, 1).Activate
End With
If Len(Dir(strfile)) > 0 Then Kill strfile
objxlboo.SaveAs strfile
objxlbook.Activate
objxl.Visible = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set objxlchart = Nothing
Set objxlsheet = Nothing
Set objxlbook = Nothing
objxl.Quit
Set objxl = Nothing
Set rs = Nothing
Set db = Nothing
End Sub

搜索更多相关主题的帖子: 代码 
2007-07-04 23:12
baiqie
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2007-1-19
收藏
得分:0 

不知道怎么传图片上来呀, 这是一个窗体,Reports为文本框
Recordsource是按钮

2007-07-04 23:19
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 

嗯,知道了。



你至少也要告诉别人你是哪行出错啊?要不然你代码全并齐,谁会花那么多时间来帮你看代码?


[此贴子已经被作者于2007-7-4 23:46:56编辑过]


VB QQ群:47715789
2007-07-04 23:19
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 

居然做的是3维的chart!但是感觉用
.SeriesCollection.Add Source:=objxlbook.Sheets("sheet1").Range("A1:B" & intloop - 1)
这个是赋值 ?有点不明白!


2007-07-05 08:50
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 
with gappExcel
lsDayValues1 = "R4C" & llTemp & ":" & "R" & llColTemp + 3 & "C" & llTemp
lsDayName1 = "R3C" & llTemp

lsDayValues2 = "R4C" & llTemp + 2 & ":" & "R" & llColTemp + 3 & "C" & llTemp + 2
lsDayName2 = "R3C" & llTemp + 2

.Charts.Add
.ActiveChart.ChartType = xlLineMarkers
.ActiveChart.Location Where:=xlLocationAsObject, Name:="sheet1"

.ActiveChart.SeriesCollection.NewSeries
.ActiveChart.SeriesCollection.NewSeries

.ActiveChart.SeriesCollection(1).Values = "=" & .ActiveSheet.Name & "!" & lsDayValues1
.ActiveChart.SeriesCollection(1).Name = "=" & .ActiveSheet.Name & "!" & lsDayName1

.ActiveChart.SeriesCollection(2).Values = "=" & .ActiveSheet.Name & "!" & lsDayValues2
.ActiveChart.SeriesCollection(2).Name = "=" & .ActiveSheet.Name & "!" & lsDayName2
.ActiveSheet.ChartObjects(llCount * 4 - 3).Width = 310
.ActiveSheet.ChartObjects(llCount * 4 - 3).Left = 70 + (418 - 70) * (llCount - 1)
.ActiveSheet.ChartObjects(llCount * 4 - 3).Top = 540
.ActiveSheet.ChartObjects(llCount * 4 - 3).Height = 170
With .ActiveChart.Axes(xlCategory)
.CrossesAt = 1
.TickLabelSpacing = 1
.TickMarkSpacing = 1
.AxisBetweenCategories = True
.ReversePlotOrder = False
End With
With .ActiveChart
.SeriesCollection(1).XValues = ""
.SeriesCollection(2).XValues = ""
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "DATE"
.Axes(xlValue, xlPrimary).HasTitle = True

.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "RMB"
End With
With .ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = objCommon.NullToString(lrRec.Fields("hmm03_storenm")) & "—" & getFormItems(lsfrmName, cstDayState) '每日状况"
End With

lsDayValues1 = "R4C" & llTemp & ":" & "R" & llColTemp + 3 & "C" & llTemp
lsDayName1 = "R3C" & llTemp

lsDayValues2 = "R4C" & llTemp + 2 & ":" & "R" & llColTemp + 3 & "C" & llTemp + 2
lsDayName2 = "R3C" & llTemp + 2

.Charts.Add
.ActiveChart.ChartType = xlLineMarkers
.ActiveChart.Location Where:=xlLocationAsObject, Name:="sheet1"

.ActiveChart.SeriesCollection.NewSeries
.ActiveChart.SeriesCollection.NewSeries

.ActiveChart.SeriesCollection(1).Values = "=" & .ActiveSheet.Name & "!" & lsDayValues1
.ActiveChart.SeriesCollection(1).Name = "=" & .ActiveSheet.Name & "!" & lsDayName1

.ActiveChart.SeriesCollection(2).Values = "=" & .ActiveSheet.Name & "!" & lsDayValues2
.ActiveChart.SeriesCollection(2).Name = "=" & .ActiveSheet.Name & "!" & lsDayName2
.ActiveSheet.ChartObjects(llCount * 4 - 3).Width = 310
.ActiveSheet.ChartObjects(llCount * 4 - 3).Left = 70 + (418 - 70) * (llCount - 1)
.ActiveSheet.ChartObjects(llCount * 4 - 3).Top = 540
.ActiveSheet.ChartObjects(llCount * 4 - 3).Height = 170
With .ActiveChart.Axes(xlCategory)
.CrossesAt = 1
.TickLabelSpacing = 1
.TickMarkSpacing = 1
.AxisBetweenCategories = True
.ReversePlotOrder = False
End With
With .ActiveChart
.SeriesCollection(1).XValues = ""
.SeriesCollection(2).XValues = ""
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "DATE"
.Axes(xlValue, xlPrimary).HasTitle = True

.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "RMB"
End With
With .ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = objCommon.NullToString(lrRec.Fields("hmm03_storenm")) & "—" & getFormItems(lsfrmName, cstDayState) '每日状况"
End With
end with
这个是我做的添加的一个新chart的示里例 看有没有帮助呢

objCommon.NullToString 其中这个函数是为了返回数据库字段为空的时候 让他不为空 而且trim掉所有空格的函数

2007-07-05 08:56
baiqie
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2007-1-19
收藏
得分:0 
回复:(心中有剑)居然做的是3维的chart!但是感觉用....

我学ACCESS,没有学VB所以我也不知道那是什么东东

2007-07-09 19:18
荒芜心田
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2007-6-7
收藏
得分:0 

学习→学习↑
2007-07-10 09:21
快速回复:代码出错了``````````
数据加载中...
 
   



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

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