2017-08-30 32 views
2

在我的工具中,我尝试创建一个形状,重命名它,让它随列的移动宽度一起移动,并将其超链接到汇总表。这是我迄今为止,预先感谢。VBA - 创建,编辑和超链接形状

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 

我知道这是不正确的,这就是为什么我伸出手,因为我找不到任何类似于我的情况。

回答

2

你很近!

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外循环
  • 一旦你与集中定义GoToSummary,你可以参考它直接,即作为GoToSummary代替.Shapes(GoToSummary)
  • 新增的超级链接以及
+0

好,只有一个问题,我如何保持形状相同的大小。有些纸张比其他纸张有更宽的列,这使得一些比其他纸张更宽。 –

+2

在超链接之前,尝试添加'GoToSummary.Placement = xlMove' 和'GoToSummary.Width = 300' –