Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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/3/wix/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中循环使用指定名称的所有对象_Vba_Powerpoint - Fatal编程技术网

如何在vba中循环使用指定名称的所有对象

如何在vba中循环使用指定名称的所有对象,vba,powerpoint,Vba,Powerpoint,我正在用vba在powerpoint中制作一个游戏,我想在所有名为“collider”的对象上循环,但它不起作用 Sub getCollision() Dim curSlide As Slide Dim curShape As Shape For Each curSlide In ActivePresentation.Slides Debug.Print curSlide.SlideNumber For Each curShape In curSlide.Shapes

我正在用vba在powerpoint中制作一个游戏,我想在所有名为“collider”的对象上循环,但它不起作用

Sub getCollision()

Dim curSlide As Slide
Dim curShape As Shape

For Each curSlide In ActivePresentation.Slides
    Debug.Print curSlide.SlideNumber
    For Each curShape In curSlide.Shapes


    If curShape.Name = collider Then
        curShape.Left = 10
    Debug.Print curShape.Name
    


    Next curShape
Next curSlide




End Sub

在您的代码中,If函数没有以end If正确结束,它将在执行时导致调试问题

      If curShape.Name = collider Then
            curShape.Left = 10
        Debug.Print curShape.Name
   end if
  • 通过将shape.name更改为带引号的,例如curShape.name=“Hello”,然后在我的例子中它可以正常工作,您可以在Powerpoint的排列>选择面板中检查形状的名称

  • 如果curShape.Name=“collider”则
    如果“collider”是形状的文字名称。您需要提供的不仅仅是“不工作”,还有什么不工作?你在任何线路上都有错误吗?尝试将
    curShape.Name=collider
    更改为
    curShape.Name=“collider”
    两件事,这将在将来为您节省大量麻烦:在每个模块的顶部添加显式选项。在VBA IDE中,选择“工具|选项”并选中“要求变量声明”,以便VBA自动添加此选项。有了它,您将得到一个关于collider(不在引号中)是未声明变量的错误。接下来,在尝试运行代码之前编译代码可以节省时间。这也会找出错误。调试|编译VBA项目