[英]Power point VBA, want to extract all words in all slides
I would like to change the style of a specific word starting and ending with a specific character (says !) 我想更改以特定字符开头和结尾的特定单词的样式(例如!)。
For example, One of the slides looks like : 例如,其中一张幻灯片如下所示:
Quiet Place 安静的地方
I have a specific character !, that indicates to be modified (change color to red) 我有一个特定的字符!,表示已被修改(将颜色更改为红色)
So, I think I need functions in VBA : 所以,我认为我需要VBA中的功能:
strtok
read all strings (possibly separated by space ' ' in each slide) 读取所有字符串(每张幻灯片中可能用空格''隔开)
output : "Quiet" "Place" "No1" "Eating" "No2" "Talking" "!No3!" 输出:“安静”“位置”“ No1”“饮食”“ No2”“交谈”“!No3!” "Sleeping" “睡眠”
strfind (strcmp)
for each word, decide whether the first and last character contains '!' 对于每个单词,请确定第一个和最后一个字符是否包含“!”
output : "!No3!" 输出:“!No3!”
myfunc
for the word with starting and ending with '!', modify it for example 'bold' 对于以“!”开头和结尾的单词,请对其进行修改,例如“ bold”
The result of such example would be : 该示例的结果将是:
Quiet Place 安静的地方
I found a code from sberry 我从sberry找到了一个代码
Sub StrModify()
Dim p As Presentation: Set p = ActivePresentation
Dim s As Slide
Dim sh As Shape
For Each s In p.Slides
For Each sh In s.Shapes
If sh.HasTextFrame Then
If sh.TextFrame.HasText Then
Debug.Print sh.TextFrame.TextRange.Text
End If
End If
Next
Next
End Sub
The output of this function is : 该函数的输出为:
Quiet Place 安静的地方
No1 Eating 一号吃
No2 Talking 2号说话
!No3! 第三! Sleeping 睡眠
which is not token by space ' ' 这不是空格''
Is there "strtok"-like function that separates "Quiet Place" to "Quiet" and "Place" ? 是否有类似“ strtok”的功能,将“安静的地方”分隔为“安静”和“地方”?
Each TextRange object has Words, Lines, Paragraphs and other collections that you can iterate through: 每个TextRange对象都有单词,行,段落和其他集合,您可以循环访问这些集合:
Dim oRng As TextRange
Dim oSh As Shape
Dim oSl As Slide
Dim x As Long
For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
For Each oRng In oSh.TextFrame.TextRange.Words
Debug.Print oRng.Text
Next
End If
End If
Next
Next
If you are going to use Steve's (good) suggestion to iterate through the words DONT use ! 如果您要使用史蒂夫的(好的)建议来迭代“不要使用”一词! as the markers.Punctuation is not seen as part of the word. 标点符号不被视为单词的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.