vba 形状未知成员:无效请求。要选择形状,其视图必须处于活动状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17221930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Shape unknown member: invalid request. To select a shape, its view must be active
提问by Daniel
I have a PowerPoint macro that takes pictures and adds them to an open slideshow. When I try to run the macro after clicking below the list of slides on the left of the screen (which causes a solid blinking horizonal bar underneath the last slide), I get the error:
我有一个 PowerPoint 宏,可以拍摄照片并将它们添加到打开的幻灯片中。当我在屏幕左侧的幻灯片列表下方单击后尝试运行宏时(这会导致最后一张幻灯片下方出现一个闪烁的水平条),我收到错误消息:
Runtime error '-2147188160 (80042240)':
Shape unknown member: invalid request. To select a shape, its view must be active
I figured this was because I didn't have a valid object selected so I added a debug statement to determine what the selection was:
我想这是因为我没有选择一个有效的对象,所以我添加了一个调试语句来确定选择是什么:
If ActiveWindow.Selection.Type = 0 Then
MsgBox "0"
End If
If ActiveWindow.Selection.Type = 1 Then
MsgBox "1"
End If
If ActiveWindow.Selection.Type = 2 Then
MsgBox "2"
End If
If ActiveWindow.Selection.Type = 3 Then
MsgBox "3"
End If
The first image to get added causes a 1
to be displayed and the picture is added correctly but then error displays and macro stops. Annoyingly, when I try to run this in debug mode, it works every time. I can only assume I'm somehow manually fixing the problem on accident when I debug it.
要添加的第一个图像会导致1
显示 a 并且正确添加了图片,但随后会显示错误并且宏停止。令人讨厌的是,当我尝试在调试模式下运行它时,它每次都有效。我只能假设我在调试时以某种方式意外地手动修复了问题。
The statement that's causing the problem:
导致问题的语句:
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(//file information//).Select
//the line after
ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
回答by Kazimierz Jawor
Assuming that you want to add your pictures when slide show is running you could do it this way, too:
假设您想在幻灯片放映时添加图片,您也可以这样做:
Dim fileName, filename1, filename2
fileName = "c:\PROJEKT\....\Hydrangeas.jpg" 'your path +file name here
fileName1 = ... 'add other file path
fileName2 = ... 'add other file path
With ActivePresentation.SlideShowWindow.View.Slide.Shapes
.AddPicture fileName, True, True, 10, 10, 100, 100
.AddPicture fileName1, True, True, 30, 30, 100, 100
.AddPicture fileName2, True, True, 50, 50, 100, 100
'...etc.
End With
Hope it will help...
希望它会有所帮助...
回答by Steve Rindsberg
I think I know what's going on here. If you/the user has clicked on the slide thumbnail in the thumbnails pane, the the active selection might be the Slide rather than the added picture.
我想我知道这里发生了什么。如果您/用户在缩略图窗格中单击了幻灯片缩略图,则活动选择可能是幻灯片而不是添加的图片。
You can get round this by doing something like this:
您可以通过执行以下操作来解决此问题:
Dim oSh as Shape
Set oSh = ActiveWindow.Selection.SlideRange.Shapes.AddPicture(//file information//)
oSh.ZOrder msoSendToBack
Just one of many reasons to use object references (oSh in this case) rather than working with a selection. ;-)
这只是使用对象引用(在本例中为 oSh)而不是使用选择的众多原因之一。;-)