vb操作excel作图
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Private Sub Command1_Click()
Dim xlapp As Object 'New
Dim xlBook As Object 'New
Dim xlSheet As Object 'New
Set xlapp = CreateObject("")
= flase
(1, 1) = "shiduan"
(1, 2) = "datetime"
(1, 3) = "x"
(1, 4) = "y"
(1, 5) = "x_t"
(1, 6) = "y_t"
+ "\"
xlapp = Nothing
End Sub
Private Sub Command2_Click()
Dim count As Integer
Dim count_b As Integer
Set xlapp = CreateObject("")
= True
On Error Resume Next
Set xlBook = + "\")
Set xlSheet = (1)
= xlMaximized
count = 11
("C2").Select
(2, 3).FormulaR1C1 = "=V ALUE(RC[+2])"
("C2").AutoFill Destination:=("C2:C" & 11), Type:=xlFillDefault
("D2").Select
(2, 4).FormulaR1C1 = "=V ALUE(RC[+2])"
("D2").AutoFill Destination:=("D2:D" & 11), Type:=xlFillDefault
count_b = 2
("C2 :D11").Select '选取区域
= "=Sheet1!R" & count_b & "C3:R" & count & "C3" 'X区域
= "=Sheet1!R" & count_b & "C4:R" & count & "C4" 'Y区域
= xlXYScatter '设置散点
Source:=Sheets("Sheet1").Range("C" & count_b & ":D" & count) '选取区域
Where:=xlLocationAsObject, Name:="Sheet1"
With 'X轴
.MinimumScale = 0 '设置最小坐标
End With
With 'Y轴
.MinimumScale = 0 'Int(min_f(a) / 100) * 1000 + 50 '设置最小坐标
.CrossesAt = 0 'Int(min_f(a) / 100) * 1000 + 50
End With
With Selection
.MarkerStyle = xlMarkerStyleDiamond
End With
Order:=3, Forward:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=False).Select
'
' With '设置标题和坐标名称
.HasTitle = True
. = "负荷气象分布图" '标题
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary). = "实感指数" 'X轴
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary). = "最大负荷(MW)" 'Y轴
End With
' = True '图表图例
' = xlTop '图例位置
' ' ' With '虚线
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
'' ' '趋势线大小,颜色
With ' .ColorIndex = curv_color '3
.Weight = xlThick 'xlThick
.LineStyle = xlGray75
End With
With .Name = "回归负荷" '曲线名称
End With
' = "=""实际负荷""" '散点名称
'调整区域大小,先选中区域
= 15
= 55
= 170
= 343
'回归函数位置
= 50
= 35
' = True
'标示调整
= 99
= 18
'标题
= 0
"图表1").ScaleHeight , msofalse, msoScaleFromTopLeft ' ' = False
+ "\" + "SHIL" + ".jpg", "jpg" '导出图片
''
''' + "\R\" + "SHILI" + ".jpg", "jpg"
Set xlapp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
DoEvents
End Sub