- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
29#
發表於 2013-7-19 09:10
| 只看該作者
回復 28# slip
試試看- Sub GetDDE()
- Dim T As Date, xMax As Integer, xMin As Integer, i As Integer
- T = Now '取得現在時間
- If Not IsError(Sheets(1).[B2]) Then
- Application.ScreenUpdating = False
- With Sheets(2).[A65536].End(xlUp).Offset(1) '物件
- i = .Row 'Row(物件屬性):列號
- .Resize(, 7) = Sheets(1).[A2:G2].Value '工作表1的資料DDE連結成功寫入工作表2
- .Range("H1") = .Range("D1") - .Range("C1") 'H欗的公式=>D欗-C欗
- .Range("I1") = .Range("H1") - .Range("H1").Offset(-1) 'I413=H413-H412......數列2
- .Range("J1") = .Range("E1") 'J欗的公式=E欗
- xMax = Application.Max(.Parent.[i:j]) '最大值
- xMin = Application.Min(.Parent.[i:j]) '最小值
- '** .Parent.ChartObjects(1): 物件 (工作表的第1個圖表) *****
- With .Parent.ChartObjects(1).Chart
- .SeriesCollection(1).Values = .Parent.Parent.Range("J2:J" & i) '指定數列資料的範圍
- .SeriesCollection(1).ChartType = 52 '指定數列圖表類型
- .SeriesCollection(2).Values = .Parent.Parent.Range("i2:i" & i)
- .SeriesCollection(2).ChartType = 65
- If .SeriesCollection(2).AxisGroup <> xlSecondary Then .SeriesCollection(2).AxisGroup = xlSecondary '數列不在第2Y座標軸(副座標): 數列指定到第2Y座標軸(副座標)
- '.AxisGroup = 2 -> 副座標
- .Parent.Top = .Parent.Parent.Range("L" & IIf(i <= 39, 1, i - 38)).Top '指定圖表頂端的位置
- With .Axes(xlValue) 'Y座標軸
- .MinimumScale = xMin
- .MaximumScale = xMax
- .MajorUnitIsAuto = True '主要刻度間距=自動設定
- .MinorUnitIsAuto = True '次要刻度間距=自動設定
- .Crosses = xlAutomatic '座標軸與其他座標軸交叉的點=自動設定
- .ScaleType = xlLinear '數值座標軸的刻度類型=xlLinear
- End With
- With .Axes(xlValue, xlSecondary) '第2Y座標軸(副座標)
- .MinimumScale = xMin
- .MaximumScale = xMax
- .MaximumScaleIsAuto = True
- .MajorUnitIsAuto = True
- .MinorUnitIsAuto = True
- .Crosses = xlAutomatic
- .ScaleType = xlLinear
- End With
- End With
- End With
- Application.ScreenUpdating = True
- End If
- Application.OnTime T + TimeValue("00:01:00"), "GetDDE" '間隔5分鐘改成TimeValue("00:05:00"),
- End Sub
複製代碼 |
|