是否可以动态控制excel 2007中文本框的位置

Mut*_*tor 5 excel vba excel-2007 excel-vba

我在仪表板项目上工作,我将有三个值:最小值,最大值和当前值.最小值和最大值将是条形的终点,我想在条形图的适当位置放置一个包含当前值的文本框.见下文:

是否可以在Excel中执行此操作,如果是这样,我将如何实现此目的.我有一些Visual Basic的经验,但我之前没有遇到过这个.

在此输入图像描述

最终,我试图在以下链接上执行仪表板的excel版本:

链接到仪表板

Kaz*_*wor 1

我喜欢你的想法,因此我检查了完整的代码是什么样子的。结果如下:

Sub SolutionShape(currentVal)

Dim shpBar As Shape, shpCurrent As Shape

'let's assume we have only two shapes on the Activesheet
Set shpBar = ActiveSheet.Shapes(1)
Set shpCurrent = ActiveSheet.Shapes(2)

Dim barMin As Double, barMax As Double
    barMin = 0.51              'both values could be taken from sheet
    barMax = 6.75

'let's do it visualy complicated this time :)
With shpCurrent
    .Left = (-.Width / 2 + shpBar.Left) + _
        (((currentVal - barMin) / (barMax - barMin)) * shpBar.Width)

    **'EDITED- adding information about current value:**
    .TextFrame.Characters.Text = currentVal
End With

End Sub
Run Code Online (Sandbox Code Playgroud)

从立即窗口的事件中调用过程进行测试,例如:

SolutionShape 0.51      'go to beginning
SolutionShape 6.75      'go to end
Run Code Online (Sandbox Code Playgroud)

无论您放置形状以及设置形状的任何新尺寸,该解决方案都将起作用。