Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
循环浏览VBA powerpoint中的单词_Vba_Loops_Powerpoint_Words - Fatal编程技术网

循环浏览VBA powerpoint中的单词

循环浏览VBA powerpoint中的单词,vba,loops,powerpoint,words,Vba,Loops,Powerpoint,Words,我是powerpoint对象模型的新手,想知道为什么下面的代码片段不起作用。代码的目的是遍历文本框,并用其小写等价物替换某些单词。我不确定我是否要正确地替换这个词…但我最困惑的是为什么程序不会“输入”if语句…即使它找到和“of”,它们都是字符串 感谢您的帮助!:) 尝试使用strcomp函数,例如 Dim str1 as String = "of" strcomp(CStr(LCase(theWord)), str1) 为什么下面的代码片段不起作用 代码片段正在工作,只是没有达到您的预期:

我是powerpoint对象模型的新手,想知道为什么下面的代码片段不起作用。代码的目的是遍历文本框,并用其小写等价物替换某些单词。我不确定我是否要正确地替换这个词…但我最困惑的是为什么程序不会“输入”if语句…即使它找到和“of”,它们都是字符串

感谢您的帮助!:)


尝试使用strcomp函数,例如

Dim str1 as String = "of"
strcomp(CStr(LCase(theWord)), str1)

为什么下面的代码片段不起作用

代码片段正在工作,只是没有达到您的预期:)

…因为每个
单词都可能包含尾随空格:
“of”
“of”

为了处理这种可能性,还需要使用
Trim
功能(您可以省略
Cstr
,因为这在这里没有任何影响):

因此,我们比较修剪后的字符串,但随后替换整个字符串,从而保留尾随空间


您可能还对
TextRange.Replace
方法感兴趣,正如Steve Rindsberg在评论中提到的那样

还要注意,您根本不需要Cstr。它只是把字符串转换成字符串。不需要。您可能还想查看.TextRange.Replace方法,该方法将保留替换文本上的任何格式。
Dim str1 as String = "of"
strcomp(CStr(LCase(theWord)), str1)
 If LCase(Trim(theWord)) = "of" Then 
     theWord.Text = LCase(theWord) 
 End If