我正在编写代码,以便在Powerpoint的所有幻灯片中删除韩语中的所有内容。
我的代码是:
Sub remove_language()
Korean = "msoLanguageIDKorean"
For Each oSlide In ActivePresentation.Slides
Dim oShape As Shape
For Each oShape In oSlide.Shapes
If oShape.HasTable Then
For r = 1 To oShape.Table.Rows.Count
For c = 1 To oShape.Table.Columns.Count
If oShape.Table.Cell(r, c).Shape.TextFrame.TextRange.LanguageID = Korean Then
oShape.Table.Cell(r, c).Shape.TextFrame.DeleteText
End If
Next
Next
Else
Set gi = oShape.GroupItems
If Not gi Is Nothing Then
If oShape.GroupItems.Count > 0 Then
For i = 0 To oShape.GroupItems.Count - 1
If oShape.GroupItems(i).TextFrame.TextRange.LanguageID = Korean Then
oShape.GroupItems(i).TextFrame.DeleteText
End If
Next
End If
Else
If oShape.TextFrame.TextRange.LanguageID = Korean Then
oShape.TextFrame.DeleteText
End If
End If
End If
Next
Next
End Sub
这是一个基于一个代码,用于在Powerpoint中具有文本的所有对象中设置语言。但是,我想删除所有韩语内容,只留下英文内容。 问题是调试器在行中出错: 设置gi = oShape.GroupItems
调试器表示只能为组访问此成员。我也不知道我是否遗漏了别的东西。
答案 0 :(得分:1)
将此代码段替换为Else和End If之间的内容。 此外,最好将DIM所有变量放在一起,并在每个模块的开头包含Option Explicit以强制执行良好实践。
Else
' There's no GroupItems object as such, so you can't
' assigned it to a variable. However, you don't really need to.
' Set gi = oShape.GroupItems
' Instead, test to see if the shape is a group:
If oShape.Type = msoGroup Then ' it's a group
If oShape.GroupItems.Count > 0 Then
' Collections are 1-based, not 0 based so this will error:
'For i = 0 To oShape.GroupItems.Count - 1
' instead, this:
For i = 1 To oShape.GroupItems.Count
If oShape.GroupItems(i).TextFrame.TextRange.LanguageID = Korean Then
oShape.GroupItems(i).TextFrame.DeleteText
End If
Next
End If
Else ' It's not a group
If oShape.TextFrame.TextRange.LanguageID = Korean Then
oShape.TextFrame.DeleteText
End If
End If ' oShape.Type = msoGroup
End If