title: ActiveWindow VBA commands to access active slide does not work on PowerPoint 2013 running on virtual machine
body: <p>I just started using VBA a few days ago. I noticed that some few commands do not seem to work on my computer and I was wondering whether this is due to my computer setup.</p>
  
  <p>I am using VBA in PowerPoint 2013 on Windows 7 run via VMware Fusion (virtual machine) on MacOSX. I need to create a dynamic reference to the active slide, but several way of doing so broke my code:</p>
  
  <pre><code>Set oSl = Application.ActiveWindow.View.Slide
  </code></pre>
  
  <p>(as suggested <a href="http://answers.microsoft.com/en-us/office/forum/office_2007-powerpoint/in-powerpoint-vba-how-do-i-refer-to-the-active/5b4a7daf-9309-4159-b648-586d75895f85" rel="nofollow noreferrer">here</a>)</p>
  
  <pre><code>Set oSl = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideNumber)
  </code></pre>
  
  <p>(as suggested <a href="http://www.msofficeforums.com/powerpoint/15060-vba-active-slide.html" rel="nofollow noreferrer">here</a>)</p>
  
  <pre><code>Set oSl = ActiveWindow.Selection.SlideRange.SlideIndex
  </code></pre>
  
  <p>(as suggested <a href="http://vba.relief.jp/powerpoint-vba-get-active-slide-number/" rel="nofollow noreferrer">here</a>)</p>
  
  <p>None of these worked for me. Since I just started using VBA I simply inserted Message Boxes after different parts of the code, and looked at when the boxes where no longer triggered - in this case always after the "oSl =" line that I replaced with the various other approaches delineated above. Additionally, </p>
  
  <pre><code>Set oSl = ActiveWindow.Selection.SlideRange(1)
  </code></pre>
  
  <p>also broke my code (as discussed <a href="https://stackoverflow.com/questions/30003173/create-animated-random-image-display-tool-in-vba">here</a>) </p>
  
  <p>What DID work so far was</p>
  
  <pre><code>Set oSl = ActivePresentation.SlideS(1)
  </code></pre>
  
  <p>All the methods above that didn't work (but should) contain "ActiveWindow". It would be great if you could advise on whether there are errors in my approach to selecting the active slide or whether the issue might be that VBA can't access the "ActiveWindow" properly because my PowerPoint runs on a virtual machine. Should that be the case, is there another way to select the currently active slide without using ActiveWindow? </p>
  
  <p>EDIT: I am trying to apply this to the following code in PowerPoint. Basically what I want to do is replace the line "oSl = ActivePresentation.SlideS(1)" with a line of code that won't always target slide 1 but whichever slide is currently active. My question is not so much HOW to do this - there are plenty of instructions on how to do it online. My question is WHY these approaches are not working for me.</p>
  
  <pre><code>Sub SelectionMacro()
  
  Dim oSl As Slide
  Dim oSh As Shape
  Dim aArrayOfShapes() As Variant
  Dim ShapeX As Shape
  Dim N As Long
  Dim Temp As Variant
  Dim J As Long
  Dim FadeEffect As Effect
  
  Set oSl = ActivePresentation.SlideS(1)
  
  'This section creates an array of all pictures on Slide1 called
  '"aArrayOfShapes"
  For Each oSh In oSl.Shapes
      If oSh.Type = msoPicture Then
          On Error Resume Next
          Debug.Print UBound(aArrayOfShapes)
          If Err.Number = 0 Then
              ReDim Preserve aArrayOfShapes(1 To UBound(aArrayOfShapes) + 1)
          Else
              ReDim Preserve aArrayOfShapes(1 To 1)
          End If
          Set aArrayOfShapes(UBound(aArrayOfShapes)) = oSh
      End If
  Next
  
  'This section creates a random index number within the bounds of the
  'length of aArrayOfShapes and assigns the shape with that index number
  'to the Shape object ShapeX
  Randomize
  NumberX = Int((UBound(aArrayOfShapes) - (LBound(aArrayOfShapes) - 1)) * Rnd) + LBound(aArrayOfShapes)
  Set ShapeX = aArrayOfShapes(NumberX)
  
  'This section shuffles aArrayOfShapes
  For N = LBound(aArrayOfShapes) To UBound(aArrayOfShapes)
      J = CLng(((UBound(aArrayOfShapes) - N) * Rnd) + N)
          If N &lt;&gt; J Then
              Set Temp = aArrayOfShapes(N)
              Set aArrayOfShapes(N) = aArrayOfShapes(J)
              Set aArrayOfShapes(J) = Temp
          End If
      Next N
  
  'This section loops through all Shapes in aArrayOfShapes and
  'fades them out one by one EXCEPT for ShapeX
  For Each Shape In aArrayOfShapes
      If ShapeX.Name &lt;&gt; Shape.Name Then
      Set FadeEffect = oSl.TimeLine.MainSequence.AddEffect _
      (Shape:=Shape, effectid:=msoAnimEffectFade, trigger:=msoAnimTriggerAfterPrevious)
          With FadeEffect
          .Timing.Duration = 0.5
          .Exit = msoTrue
          End With
      End If
  Next Shape
  
  End Sub
  </code></pre>