HasTextFrame – No access to text of group objects

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

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

  1. Sub B Macro()
  2. '
  3. ' B Macro
  4. '
  5. Dim wks As Worksheet
  6. Dim numShapes, numAutoShapes, i As Long
  7. For Each wks In Worksheets
  8. With wks.Shapes
  9. numShapes = .Count
  10. If numShapes > 1 Then
  11. numTextShapes = 0
  12. For i = 1 To numShapes
  13. If .Item(1).HasTextFrame Then
  14. content = .Item(1).TextFrame.Characters.Text
  15. MsgBox "Text: " & sMsg
  16. End If
  17. Next
  18. End If
  19. End With
  20. Next wks
  21. '
  22. End Sub

答案1

得分: 1

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

  1. Sub BMacro()
  2. Dim wks As Worksheet, numTextShapes As Long, shp As Shape
  3. Dim numShapes As Long, itm As Shape
  4. For Each wks In Worksheets
  5. numShapes = wks.Shapes.Count
  6. If numShapes > 1 Then
  7. numTextShapes = 0
  8. For Each shp In wks.Shapes
  9. If shp.Type <> msoGroup Then 'not a group?
  10. Debug.Print ShapeText(shp)
  11. Else
  12. For Each itm In shp.GroupItems 'loop grouped items
  13. Debug.Print ShapeText(itm)
  14. Next
  15. End If
  16. Next shp
  17. End If
  18. Next wks
  19. End Sub
  20. Function ShapeText(shp As Shape) As String
  21. If Not shp.HasChart Then 'ignore chartobjects
  22. On Error Resume Next 'ignore error if no textframe...
  23. ShapeText = shp.TextFrame.Characters.Text
  24. End If
  25. 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:

  1. Sub BMacro()
  2. Dim wks As Worksheet, numTextShapes As Long, shp As Shape
  3. Dim numShapes As Long, itm As Shape
  4. For Each wks In Worksheets
  5. numShapes = wks.Shapes.Count
  6. If numShapes &gt; 1 Then
  7. numTextShapes = 0
  8. For Each shp In wks.Shapes
  9. If shp.Type &lt;&gt; msoGroup Then &#39;not a group?
  10. Debug.Print ShapeText(shp)
  11. Else
  12. For Each itm In shp.GroupItems &#39;loop grouped items
  13. Debug.Print ShapeText(itm)
  14. Next
  15. End If
  16. Next shp
  17. End If
  18. Next wks
  19. End Sub
  20. Function ShapeText(shp As Shape) As String
  21. If Not shp.HasChart Then &#39;ignore chartobjects
  22. On Error Resume Next &#39;ignore error if no textframe...
  23. ShapeText = shp.TextFrame.Characters.Text
  24. End If
  25. 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:

确定