HasTextFrame – No access to text of group objects

huangapple go评论57阅读模式
英文:

HasTextFrame - No access to text of group objects

问题

我有20个工作簿,不能更新以下附加在图表顶部并出现在每个工作表上的Group对象的文本(标题1金额1...)。

要更新的Group对象的文本

出现的错误似乎与'If .Item(1).HasTextFrame Then'这一行有关。你能提供一些线索吗?
谢谢你的时间和考虑。

英文:

I have 20 workbooks and cannot update the text (title 1 amount 1...) of the following Group objects added on top of graphs and appearing on each sheet.

Text of Group objects to be updated

The error coming up is with the 'If .Item(1).HasTextFrame Then' line apparently.
Can you provide me with the clue to this please?
Thank you for your time and consideration

Sub B Macro()
'
' B Macro
'
Dim wks As Worksheet
Dim numShapes, numAutoShapes, i As Long

    For Each wks In Worksheets
        With wks.Shapes
            numShapes = .Count
            
            If numShapes > 1 Then

                numTextShapes = 0
                For i = 1 To numShapes
                    If .Item(1).HasTextFrame Then
                        content = .Item(1).TextFrame.Characters.Text
MsgBox "Text: " & sMsg
                    End If
                Next
            End If
            End With
    Next wks
    '
End Sub

答案1

得分: 1

HasTextFrameShapeRange 的属性,而不是 Shape 的属性。如果您只想检查文本内容,可以像这样操作:

Sub BMacro()

    Dim wks As Worksheet, numTextShapes As Long, shp As Shape
    Dim numShapes As Long, itm As Shape
    
    For Each wks In Worksheets
        numShapes = wks.Shapes.Count
        If numShapes > 1 Then
            numTextShapes = 0
            For Each shp In wks.Shapes
                If shp.Type <> msoGroup Then        'not a group?
                    Debug.Print ShapeText(shp)
                Else
                    For Each itm In shp.GroupItems  'loop grouped items
                        Debug.Print ShapeText(itm)
                    Next
                End If
            Next shp
        End If
    Next wks
End Sub

Function ShapeText(shp As Shape) As String
    If Not shp.HasChart Then   'ignore chartobjects
        On Error Resume Next   'ignore error if no textframe...
        ShapeText = shp.TextFrame.Characters.Text
    End If
End Function

Note: I have provided the translation as requested, and I won't answer translation-related questions.

英文:

HasTextFrame is a property of ShapeRange and not of Shape. If you just want to check for text content you could do something like this:

Sub BMacro()

    Dim wks As Worksheet, numTextShapes As Long, shp As Shape
    Dim numShapes As Long, itm As Shape
    
    For Each wks In Worksheets
        numShapes = wks.Shapes.Count
        If numShapes &gt; 1 Then
            numTextShapes = 0
            For Each shp In wks.Shapes
                If shp.Type &lt;&gt; msoGroup Then        &#39;not a group?
                    Debug.Print ShapeText(shp)
                Else
                    For Each itm In shp.GroupItems  &#39;loop grouped items
                        Debug.Print ShapeText(itm)
                    Next
                End If
            Next shp
        End If
    Next wks
End Sub

Function ShapeText(shp As Shape) As String
    If Not shp.HasChart Then   &#39;ignore chartobjects
        On Error Resume Next   &#39;ignore error if no textframe...
        ShapeText = shp.TextFrame.Characters.Text
    End If
End Function

huangapple
  • 本文由 发表于 2023年5月8日 01:15:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定