基于输入数据在Excel工作表中移动形状

时间:2016-01-25 02:13:40

标签: excel vba excel-vba

我正在考虑在Excel中制作一个时间轴,根据日期在时间轴上移动一个“窗口”(白色椭圆)。 enter image description here

我正在做的是VBA:

  1. 设置比例(整个箭头为一年)
  2. 设置椭圆的初始位置
  3. 设置椭圆的新位置(基于日期在时间轴上的距离)
  4. 我对VBA完全不熟悉,并且想知道是否有人能指出我正确的方向?

    谢谢!

2 个答案:

答案 0 :(得分:0)

...试

Sub Macro1()

Dim shp As Shape
For Each shp In ActiveSheet.Shapes
    If shp.Type = 1 Then
        shp.Delete
    End If
Next shp

ActiveSheet.Shapes.AddShape Type:=msoShapeOvalCallout, Left:=100, Top:=100, Width:=200, Height:=150
ActiveSheet.Shapes(1).TextFrame2.TextRange.Characters.Text = "Hello people!"

Application.ScreenUpdating = True

Application.Wait (Now + TimeValue("00:00:03"))

For i = 1 To 25 Step 1
    ActiveSheet.Shapes(1).IncrementLeft -4
    ActiveSheet.Shapes(1).IncrementTop i
    Application.Wait (Now + 0.000009)
Next i

End Sub

答案 1 :(得分:0)

怎么样?

Sub Macro1()

Dim shp As Shape
For Each shp In ActiveSheet.Shapes
    If shp.Type = 1 Then
        shp.Delete
    End If
Next shp

If ActiveSheet.Range("A1").Value = 1 Then
    ActiveSheet.Shapes.AddShape Type:=msoShapeOvalCallout, Left:=100, Top:=0, Width:=200, Height:=150
End If

If ActiveSheet.Range("A1").Value = 2 Then
    ActiveSheet.Shapes.AddShape Type:=msoShapeOvalCallout, Left:=100, Top:=50, Width:=200, Height:=150
End If

'and so on...
End Sub