0

根据我不久前提出的以下查询,我已经将文本框输入到公式中...

VBA Excel如何在文本框中编写Excel公式

一切都很好,但是我在将正确的字体功能输入到这个文本框中时遇到了问题。

基本上我有两组独立的代码,我很想将它们组合成一个

Sub Duct1()
   Set myDocument = ActiveSheet
   With myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 300, 140, 180, 30)
    .name = "Duct1"
      With .TextFrame
     .HorizontalAlignment = xlLeft
        With .Characters
        .Text = "1W-20mm/90' upturn"
        .Font.ColorIndex = 3
        .Font.Size = 16
        .Font.Bold = True
     End With
     End With
     .Rotation = 25
     .Fill.Visible = False
     .Line.Visible = False
   End With
 End Sub

  Sub Duct1Desc()
  ActiveSheet.Shapes("Duct1").OLEFormat.Object.Formula = "=AB1"
  End Sub

对于我也尝试过的第二个代码:

 Sub Duct1Desc()
 ActiveSheet.Shapes("Duct1").OLEFormat.Object.Formula = "=AB1"
 With ActiveSheet.Shapes("Duct1")
 .Font.ColorIndex = 3
 .Font.Size = 16
 .Font.Bold = True
 End With
 End Sub

但在这个问题中,我遇到了一个错误,即 VBA 不支持此属性或方法。

谁能帮我把这两个代码绑定在一起?

谢谢在此处输入图像描述

4

1 回答 1

0

这对我有用:

Dim s As Shape

Set s = ActiveSheet.Shapes("myBox")
s.DrawingObject.Formula = "=B2"

好的,我认为问题在于链接,而不是格式:这对我有用。

Sub Duct1Desc()
    Dim s
    Set s = ActiveSheet.Shapes("Duct1")
    s.OLEFormat.Object.Formula = "=A1"
    With s.DrawingObject
        .Font.ColorIndex = 3
        .Font.Size = 20
        .Font.Bold = True
    End With
End Sub
于 2020-04-21T16:57:10.947 回答