我正在尝试复制Powerpoint 2007中“查找”按钮的行为。我已经能够编写vba来查找我要搜索的文本,但我想将包含文本的形状带到中心主窗口。我的代码选择了正确的幻灯片和形状,它只是不可见。
ppt.Presentations.open(strFloorPlan)
For each sld in ppt.Activepresentation.Slides
For each shp in sld.shapes
if shp.hasTextFrame then
set txtrng = shp.textFrame.TextRange
set foundtext =txtrnd.Find(findwhat:="A string representing my search criteria)
do while not (foundtext is nothing)
sld.select 'This works
shape.select 'This works
**At this point I have my text selected, but is off screen. I would like it to be in the current ppt window, so the users do not net to find it.**
Loop
End if
Next
Next
答案 0 :(得分:1)
这会让你走近:
ActiveWindow.ScrollIntoView shp.Left, shp.Top, shp.Width, shp.Height
确保由您提供的坐标(即形状的坐标)限定的区域完全在视野中。但是,它不会使当前视图中的形状居中。
答案 1 :(得分:0)
添加以下内容以将搜索找到的形状位置更改为屏幕中心(前提是形状小于演示文稿):
shp.Top = (ActivePresentation.PageSetup.SlideHeight - shp.Height) / 2
shp.Left = (ActivePresentation.PageSetup.SlideWidth - shp.Width) / 2