Set application = WScript.CreateObject("PowerPoint.Application") ' SlideShowWindows is when the pp is in presentation mode If application.SlideShowWindows.Count > 0 Then Call Err.Raise(60002, , "PowerPoint is in presentation mode. Cannot perform operation.") Else ' Run when not in presentation mode, select the first slide of the current section currentSlide = application.ActiveWindow.Selection.SlideRange.Item(1).SlideIndex End If ' Get the current section index currentSection = application.ActivePresentation.Slides(currentSlide).sectionIndex ' Get the state of the section isExpanded = application.ActiveWindow.IsSectionExpanded(currentSection) If isExpanded Then ' Collapse the section collapse = application.ActiveWindow.ExpandSection(currentSection, False) Else ' Expand the section expand = application.ActiveWindow.ExpandSection(currentSection, True) End If