xyj697400 发表于 2020-4-14 23:15:38

利用VBA批量替换PPT中图例的文字内容

批量将PPT中图表的文字内容进行替换,自带的查找替换只能替换正文内容

firesignal 发表于 2020-4-15 01:16:34

有大神不?求教

俞承凤 发表于 2020-4-15 02:30:29

@weiyingde,老师,求教

1921450080 发表于 2020-4-15 02:40:18

Sub ReplaceText()
    Dim oSld As Slide
    Dim oShp As Shape
    Dim oTxtRng As TextRange
    Dim oTmpRng As TextRange
    Set oSld = Application.ActivePresentation.Slides(1)
    For Each oShp In oSld.Shapes
Set oTxtRng = oShp.TextFrame.TextRange
      Set oTmpRng = oTxtRng.Replace(FindWhat:="华东", _
            Replacewhat:="huadong", WholeWords:=True)
      Do While Not oTmpRng Is Nothing
            Set oTxtRng = oTxtRng.Characters(oTmpRng.Start + oTmpRng.Length, _
                oTxtRng.Length)
            Set oTmpRng = oTxtRng.Replace(FindWhat:="华东", _
                Replacewhat:="huadong", WholeWords:=True)
      Loop
    Next oShp
End Sub
这个运行没实现

faxianwang 发表于 2020-4-15 03:03:56

这是样本

hexiyuan 发表于 2020-4-15 04:31:53

Sub ReplaceText()
    Dim Sd As Slide, Wk As Object, Rng, Rp
    Set Sd = ActivePresentation.Slides(1)
    '图形中的工作簿对象
    Set Wk = Sd.Shapes(3).Chart.ChartData.Workbook
    '工作簿中的工作表数据范围
    Set Rng = Wk.WorkSheets(1).Range("A1:N3")
    '执行替换操作
    Rp = Rng.Replace("北方", "BeiFang", 1)
End Sub
页: [1]
查看完整版本: 利用VBA批量替换PPT中图例的文字内容