如何使用VBA替换整个powerpoint(包括表格)中的单词?

如何使用VBA替换整个powerpoint(包括表格)中的单词?,vba,powerpoint,str-replace,Vba,Powerpoint,Str Replace,我必须通过大量的功能点,用新的单词替换特定的单词。我制作了一个宏,看起来很有效,但仔细检查后,我意识到表中的单词并没有被替换。经过一番调查,我看到其他人也有这个问题,但没有明确的答案。我提出了以下建议,但在读取shp.GroupItems中每个grpItem的的行中,我还收到运行时错误“此成员只能为组访问” 是否有人能提供我做错了什么的见解,或者提供更好的方法 Sub DataScrubAllSlidesAndTables() Dim sld As Slide Dim grpI

我必须通过大量的功能点,用新的单词替换特定的单词。我制作了一个宏,看起来很有效,但仔细检查后,我意识到表中的单词并没有被替换。经过一番调查,我看到其他人也有这个问题,但没有明确的答案。我提出了以下建议,但在读取shp.GroupItems中每个grpItem的
的行中,我还收到运行时错误“此成员只能为组访问”

是否有人能提供我做错了什么的见解,或者提供更好的方法

 Sub DataScrubAllSlidesAndTables()
    Dim sld As Slide
    Dim grpItem As Shape
    Dim shp As Shape

For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

        If shp.HasTextFrame Then
            If shp.TextFrame.HasText Then
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Store", "Seller")
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Customer", "Buyer")
            End If
        End If

        If shp.Type = msoTable Then
                For Each grpItem In shp.GroupItems
                    If InStr(1, grpItem.Name, "Rectangle") Then
                        grpItem.TextFrame.TextRange.Text = Replace(grpItem.TextFrame.TextRange.Text, "Store", "Seller")
                        grpItem.TextFrame.TextRange.Text = Replace(grpItem.TextFrame.TextRange.Text, "Store", "Seller")
                    End If
                Next grpItem
        End If

    Next shp
Next
End Sub
尝试使用以下方法:

 Sub DataScrubAllSlidesAndTables()
    Dim sld As Slide
    Dim grpItem As Shape
    Dim shp As Shape
    Dim i As Integer
    Dim j As Integer
    Dim varTemp As Variant
    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

        If shp.HasTextFrame Then
            If shp.TextFrame.HasText Then
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Store", "Seller")
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Customer", "Buyer")
            End If
        End If

        On Error GoTo lblNotTable:
        For i = 1 To shp.Table.Rows.Count
            For j = 1 To shp.Table.Columns.Count
            varTemp = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text
            Next j
        Next i
lblNotTable:
        Err.Clear


    Next shp
Next
End Sub
这:

轻松

这两行需要更改为: 形状暗淡 将shp变暗为形状

致:


应该可以了。

谢谢您的快速回复。我得到一个错误,上面写着“对象‘形状’的‘表格’方法在读取i=1到shp.Table.Rows.Count的
行失败
您使用的excel版本是什么?抱歉,我是指power point。你复制了我在上面写的全部代码吗?当你使用你提供给我的代码时,你会知道如何检查整个单词和大小写匹配吗?函数“Replace(FindWhat、replacehat、After、MatchCase、WholeWords)”似乎不适用于powerpoint,或者至少在本例中不适用。
 Sub DataScrubAllSlidesAndTables()
    Dim sld As Slide
    Dim grpItem As Shape
    Dim shp As Shape
    Dim i As Long
    Dim j As Long

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

        If shp.HasTextFrame Then
            If shp.TextFrame.HasText Then
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Store", "Seller")
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Customer", "Buyer")
            End If
        End If

        If shp.HasTable Then
            For i = 1 To shp.Table.Rows.Count
                For j = 1 To shp.Table.Columns.Count
                shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text = _
                    Replace(shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text, "This", "That")
                Next j
            Next i
        End If

    Next shp
Next
End Sub
Dim grpItem As Powerpoint.Shape
Dim shp As Powerpoint.Shape