VBA-创建、编辑和超链接形状

VBA-创建、编辑和超链接形状,vba,excel,shape,Vba,Excel,Shape,在我的工具中,我尝试创建一个形状,重命名它,让它随着列宽度的变化而移动,并将其超链接到摘要表。这是我到目前为止所拥有的,提前谢谢 For s = 7 To Sheets.Count With Sheets(s) Dim GoToSummary As Shape Set GoToSummary = .Shapes.AddShape(msoShapeRoundedRectangle, 400, 153 + 12.75 * 2, 300, 50)

在我的工具中,我尝试创建一个形状,重命名它,让它随着列宽度的变化而移动,并将其超链接到摘要表。这是我到目前为止所拥有的,提前谢谢

For s = 7 To Sheets.Count
    With Sheets(s)
        Dim GoToSummary As Shape
        Set GoToSummary = .Shapes.AddShape(msoShapeRoundedRectangle, 400, 153 + 12.75 * 2, 300, 50)

        .Shapes(GoToSummary).TextFrame.Characters.Text = "Go Back To Summary"
    End With
Next s  
我知道这是不正确的,这就是为什么我要伸出援手,因为我找不到任何与我的处境类似的东西。

你非常接近

Sub test()
Dim GoToSummary As Shape

For s = 7 To Sheets.Count
    Set GoToSummary = Sheets(s).Shapes.AddShape(msoShapeRoundedRectangle, 400, 153 + 12.75 * 2, 300, 50)
    GoToSummary.TextFrame.Characters.Text = "Go Back To Summary"
    Sheets(s).Hyperlinks.Add Anchor:=GoToSummary, Address:="", SubAddress:="Summary!A1"
Next s

End Sub
  • Dim GoToSummary
    循环外部
  • 一旦用Set定义了GoToSummary,就可以直接引用它,即作为
    GoToSummary
    而不是
    。Shapes(GoToSummary)
  • 还添加了超链接

太好了,只有一个问题,如何保持形状大小不变。某些工作表的列比其他工作表宽,这使得某些工作表的列比其他工作表宽。在超链接行之前,请尝试添加
GoToSummary.Placement=xlMove
GoToSummary.Width=300