英文:
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
HasTextFrame
是 ShapeRange
的属性,而不是 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 > 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论