Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
End Sub
Sub auto_open()
'
' Macro1 Macro
' 宏由 wb 录制,时间: 2007-11-5
'
'
Do While ActiveSheet.ChartObjects.Count > 0 '循环把一个表中的所有图表删除掉
ActiveSheet.ChartObjects(1).Delete
Loop
Charts.Add
Dim num As Integer '声明一个Int型对象
Application.OnKey "^c", "" '禁止复制,剪切
Application.OnKey "^x", ""
Application.OnKey "^{INSERT}", ""
num = Sheets("sheet1").UsedRange.Rows.Count ' 获得行数
Debug.Print num
ActiveChart.ChartType = xlLineMarkers ' 线性
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("D:D"), PlotBy:=xlColumns ' 绑定数据列
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" ' 将图表放在什么位置
Windows("book.xls").Activate '指定xls 文件
ActiveSheet.ChartObjects(1).Activate '选择工作表中的图表
ActiveChart.ChartArea.Select '选中当前图表区域
ActiveSheet.Shapes(1).Top = Range("A" & num + 1).Top '设置位置
ActiveSheet.Shapes(1).Left = Range("A1").Left
ActiveSheet.Shapes(1).Width = 400
ActiveSheet.Shapes(1).Height = 230
ActiveWorkbook.Save '保存
ActiveSheet.ChartObjects(1).Activate
End Sub