使用vba从powerpoint中的文本中查找数字?
我知道这个问题已经被问过,但这里有一些不同的场景。
所以我想从整个文本区域搜索整数。如果找到,则检查其小数位数是否大于 2(例如,如果 numberfound=13.656,则四舍五入为 13.66),如果没有,则四舍五入。
因此,如果在一个文本区域中有多个整数,那么它应该检查所有这些整数。
当我尝试编写代码来查找特定字符或数字时。但我不知道如何找到整个整数(意味着没有从 0 到 9)。
下面是我查找指定字符的代码:
Sub FindNumber()
Dim oSld As Slide
Dim oShp As Shape
Dim oShapes As Shapes
Dim TxtRng as variant
Dim foundText as variant
Dim no(10) As Variant
For Each oSld In ActivePresentation.Slides
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.HasTextFrame Then
If oShp.HasTextFrame Then
Set TxtRng = oShp.TextFrame.TextRange
Set foundText = TxtRng.Find(Findwhat:="0")
sno = oSld.SlideNumber
Do While Not (foundText Is Nothing)
With foundText
Set foundText = _
TxtRng.Replace(Findwhat:="0",After:=.start + .length -1 )
End With
Loop
End If
End If
Next oShp
Next oSld
End Sub
有什么办法可以做到同样的事情。
谢谢
I know this question is already ask but here is some different scenario.
So i wants to search integer from whole textarea. If found then check is it have decimals number more than 2 (e.g. if numberfound=13.656 then round off to 13.66 ) if no then round off it.
so if in one textarea there is more than one integer then it should check all of those.
As i try to write code for finding specific character or number. but i am not getting it how to find whole integer(means no from 0 To 9).
Below is my code for finding specified character :
Sub FindNumber()
Dim oSld As Slide
Dim oShp As Shape
Dim oShapes As Shapes
Dim TxtRng as variant
Dim foundText as variant
Dim no(10) As Variant
For Each oSld In ActivePresentation.Slides
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.HasTextFrame Then
If oShp.HasTextFrame Then
Set TxtRng = oShp.TextFrame.TextRange
Set foundText = TxtRng.Find(Findwhat:="0")
sno = oSld.SlideNumber
Do While Not (foundText Is Nothing)
With foundText
Set foundText = _
TxtRng.Replace(Findwhat:="0",After:=.start + .length -1 )
End With
Loop
End If
End If
Next oShp
Next oSld
End Sub
Is there any way to do the same.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有仔细检查你的代码,但它无法工作,因为你正在搜索“0”。数字不必包含零。
下面我给出了一个函数,它接受一个字符串并返回它,并根据需要舍入数字。在您的代码中调用它。
我包括我的测试数据。我建议您将文本框中的文本复制到此测试例程中。
I have not examined your code very carefully but it cannot work because you are searching for "0". A number need not contain zero.
Below I give a function that takes a string and returns it with the numbers rounded as you require. Call it within your code.
I include my test data. I recommend you copy text from your text boxes into this test routine.
这实际上是一个注释而不是一个答案,但是注释不允许代码格式化,所以我们就在这里。这部分不太正确:
相反,它应该是:
This is really a comment rather than an answer, but comments don't allow code formatting, so here we are. This part isn't quite right:
Instead, it should be: