ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1464|回复: 7

[求助] word里加粗的内容如何在PPT里统一成黄色

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-7-26 12:00 | 显示全部楼层 |阅读模式
各位大神,请教一个困惑已久的问题。因工作需要,经常需要把word的内容复制到PPT里,但是word里有很多内容加了粗,粘贴到PPT里就没有加粗了,PPT的要求是:强调的内容统一成黄色。

我可以在word里把强调的内容前后加上特殊符号,例如做成这样:#强调内容$,想问下大神,怎么在PPT中一次性把“#$”这两个符号中间的内容统一成黄色
问题.rar (594.66 KB, 下载次数: 7)



先谢过各位大神了

问题.rar

74.67 KB, 下载次数: 7

TA的精华主题

TA的得分主题

发表于 2018-7-27 13:03 | 显示全部楼层
你的ppt里不是有现成的代码么?只需要改一下正则就行了。

Sub PptRegexMatch2() '正则查找/替换
' 好吧,你打开PowerPoint的查找/替换,就知道有多坑!!!
' 好吧,用VBScript的正则功能来弥补,来增强
' 正则可以自拟,参考:http://msdn.microsoft.com/en-us/library/ms974570.aspx
' 颜色值亦可自拟。。。
    Dim oSld As Slide, oShp As Shape
    Dim lRGB As Long
    Dim strPattern As String
    Dim oRange As TextRange
    Dim i As Integer, iPos As Integer, iLen As Integer
    ' 正则相关变量
    Dim regx As Object
    Dim oMatch As Object

    ' 这里写颜色值
    lRGB = RGB(255, 255, 0)
    ' 这里写查找的正则
    'strPattern = "【(例\d+.*?|答案|考点|解析)】"
    strPattern = "(\#.*?\$)" '#$

    Set regx = CreateObject("vbscript.regexp")
    With regx
        .Global = True
        .IgnoreCase = True
        .Pattern = strPattern
    End With

    For Each oSld In ActivePresentation.Slides
        For Each oShp In oSld.Shapes
            If oShp.HasTextFrame Then
                If oShp.TextFrame.HasText Then

                    Set oRange = oShp.TextFrame.TextRange

                    With oShp.TextFrame.TextRange
                        ' 可能会出现多个匹配项的
                        If (regx.test(.Text) = True) Then
                            Set oMatch = regx.Execute(.Text)
                            For i = 0 To oMatch.Count - 1
                                'Debug.Print oMatch(i).Value
                                iPos = oMatch(i).Firstindex
                                iLen = oMatch(i).Length
                                oRange.Characters(iPos + 1, iLen).Font.Color.RGB = lRGB
                            Next i
                        End If
                    End With

                End If
            End If

        Next oShp
    Next oSld

    Set regx = Nothing
End Sub

经测试上面代码,2010版中没问题,2003版中有小问题,要适当修改。

TA的精华主题

TA的得分主题

发表于 2018-7-27 20:45 | 显示全部楼层
leikaiyi123 发表于 2018-7-27 13:03
你的ppt里不是有现成的代码么?只需要改一下正则就行了。

Sub PptRegexMatch2() '正则查找/替换

楼主说:把“#$”这两个符号中间的内容统一成黄色。不应该包括“#$”符号
oRange.Characters(iPos + 2, iLen - 2).Font.Color.RGB = lRGB

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-8-6 14:27 | 显示全部楼层
leikaiyi123 发表于 2018-7-27 13:03
你的ppt里不是有现成的代码么?只需要改一下正则就行了。

Sub PptRegexMatch2() '正则查找/替换

试了下,没问题,太感谢您了,帮了我大忙

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-8-8 17:14 | 显示全部楼层
leikaiyi123 发表于 2018-7-27 13:03
你的ppt里不是有现成的代码么?只需要改一下正则就行了。

Sub PptRegexMatch2() '正则查找/替换

大神,这个宏对文本框有效,如何让他对表格也有效呢?

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-8-8 17:15 | 显示全部楼层
dongdonggege 发表于 2018-7-27 20:45
楼主说:把“#$”这两个符号中间的内容统一成黄色。不应该包括“#$”符号
oRange.Characters(iPos + 2,  ...

运行完宏,把#$删掉就行了,所以不用处理符号。多谢您的严谨!

TA的精华主题

TA的得分主题

发表于 2018-8-10 11:12 | 显示全部楼层
dongdonggege 发表于 2018-7-27 20:45
楼主说:把“#$”这两个符号中间的内容统一成黄色。不应该包括“#$”符号
oRange.Characters(iPos + 2,  ...

增加了包含表格的判断,为什么正则没执行,帮忙看下?谢谢。
Sub PptRegexMatch2()    '正则查找/替换-----把文中“#$”两个符号之间的内容变成黄色,ppt2010版通过,ppt2003版分段后有问题
' 好吧,你打开PowerPoint的查找/替换,就知道有多坑!!!
' 好吧,用VBScript的正则功能来弥补,来增强
' 正则可以自拟,参考:http://msdn.microsoft.com/en-us/library/ms974570.aspx
' 颜色值亦可自拟。。。
    Dim oSld As Slide, oShp As Shape
    Dim lRGB As Long
    Dim strPattern As String
    Dim oRange As TextRange
    Dim i As Integer, iPos As Integer, iLen As Integer
    ' 正则相关变量
    Dim regx As Object
    Dim oMatch As Object
    Dim oRow As Row

    ' 这里写颜色值
    lRGB = RGB(255, 255, 0)
    ' 这里写查找的正则
    'strPattern = "【(例\d+.*?|答案|考点|解析)】"
    strPattern = "(\#.*?\$)"    '"\#.*?\$"

    Set regx = CreateObject("vbscript.regexp")
    With regx
        .Global = True
        .IgnoreCase = True
        .Pattern = strPattern
    End With

    For Each oSld In ActivePresentation.Slides
        For Each oShp In oSld.Shapes
            If oShp.HasTable Then
                For Each oRow In oShp.Table.Rows
                    For j = 1 To oRow.Cells.Count
                        If oRow.Cells(j).Shape.TextFrame.HasText Then
                            Set oRange = oRow.Cells(j).Shape.TextFrame.TextRange
                            With oRow.Cells(j).Shape.TextFrame.TextRange
                                If (regx.test(.Text) = True) Then '为什么这个判断执行不了?
                                    Set oMatch = regx.Execute(.Text)
                                    For i = 0 To oMatch.Count - 1
                                        iPos = oMatch(i).Firstindex
                                        iLen = oMatch(i).Length
                                        oRange.Characters(iPos + 2, iLen - 2).Font.Color.RGB = lRGB
                                    Next i
                                End If
                            End With
                        End If
                    Next j
                Next
            End If

            If oShp.HasTextFrame Then
                If oShp.TextFrame.HasText Then
                    Set oRange = oShp.TextFrame.TextRange
                    With oShp.TextFrame.TextRange
                        If (regx.test(.Text) = True) Then
                            Set oMatch = regx.Execute(.Text)
                            For i = 0 To oMatch.Count - 1
                                iPos = oMatch(i).Firstindex
                                iLen = oMatch(i).Length
                                oRange.Characters(iPos + 2, iLen - 2).Font.Color.RGB = lRGB
                            Next i
                        End If
                    End With

                End If
            End If
        Next oShp
    Next oSld
    Set regx = Nothing
End Sub

ppt正则查找替换2010.rar

525 KB, 下载次数: 4

针对表格的正则没执行

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-8-11 11:50 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-24 01:44 , Processed in 0.035985 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表