删除 Powerpoint 中的所有韩语内容

Remove all Korean content in a Powerpoint

我正在编写代码以删除 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

调试器说这个成员只能为一个组访问。另外我不知道我是否遗漏了其他东西。

将此代码段替换为上面 Else 和 End If 之间的内容。 此外,最好始终将所有变量调暗并在每个模块的开头包含 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