📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
Caption = "Form2"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form2"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.ListBox List1
Height = 600
Left = 840
TabIndex = 2
Top = 2160
Width = 2295
End
Begin VB.ComboBox Combo2
Height = 300
Left = 960
TabIndex = 1
Text = "Combo1"
Top = 1440
Width = 2055
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 615
Left = 1080
TabIndex = 0
Top = 600
Width = 1215
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Contral_Excel_97()
End Sub
Private Sub Command1_Click()
Dim x1 As Excel.Application '注释:声明显式数据类型
Set x1 = CreateObject("Excel.Application")
'注释: 创建新实例
x1.Workbooks.Add
'添加新工作簿
x1.Range("A1").Value = 5 'A1格赋值
x1.Range("A2").Value = 8 'A2格赋值
x1.Range("A3").Value = 16 'A3格赋值
x1.Range("A4").Value = 7 'A4格赋值
x1.Range("B1").Value = 2 'A1格赋值
x1.Range("B2").Value = 3 'A2格赋值
x1.Range("B3").Value = 4 'A3格赋值
x1.Range("B4").Value = 5 'A4格赋值
x1.Charts.Add
'插入图形
x1.ActiveChart.ChartType = xl3DColumnClustered
'柱状图
x1.ActiveChart.SetSourceData x1.Sheets("Sheet1").Range("A1:B4")
PlotBy = x1Columns
'图形数据来源
With x1.ActiveChart
'图标题
.HasTitle = False '没有总标题
' .Axes(x1Category, x1Primary).HasTitle = False
'.Axes(x1Value, x1Primary).HasTitle = True
'有Y轴标题
' .Axes(x1Value, x1Primary).AxisTitle.Characters
' .Text = "销售电视机(台)"
End With
With x1.ActiveChart.PageSetup '图形页面设置
.CenterHeader = "&28" & Combo2.ListIndex & "逐日 电视机销售"
'标题
.CenterFooter = "&12x x x 商场" '下边落款
.RightFooter = Format(Now, "yyyy-m-d-h:n")
'右下角显示时间
' .Orientation = x1Landscape '打印纸页面横向
End With
x1.ActiveChart.PlotArea.Interior.ColorIndex = x1None
'无背景色
x1.Workbooks(1).SaveAs "c:\aaa.xls"
'x1.ActiveWindow.SelectedSheets.PrintPreview
'打印预览
x1.Visible = True
'显示图形
Set x1 = Nothing
'交还控制句柄
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -