Set WshShell = WScript.CreateObject("WScript.Shell") Set application = WScript.CreateObject("PowerPoint.Application") ' Get arguments If WScript.Arguments.Length > 0 Then section_title = WScript.Arguments(0) is_rename = WScript.Arguments(1) Else Call Err.Raise(60003, , "Section title is not provided") End If If application.SlideShowWindows.Count > 0 Then ' Run when in presentation mode currentSlide = application.SlideShowWindows.Item(1).View.CurrentShowPosition Else ' Run when not in presentation mode On Error Resume Next ' Start error handling ' Slect the first slide of the current section currentSlide = application.ActiveWindow.Selection.SlideRange.Item(1).SlideIndex If Err.Number <> 0 Then ' If an error occurred, mean user don't select any slide, we trigger the hotkey to add a new section WshShell.AppActivate("PowerPoint") WshShell.SendKeys "%" WshShell.SendKeys "H" WshShell.SendKeys "T1" WshShell.SendKeys "A" WshShell.SendKeys "{ENTER}" ' Add section by sending hotkey leads to can't set the section title, so we rename the section WScript.Echo "rename new section" Err.Clear ' Clear the error WScript.Quit ' Stop the execution of the script End If On Error GoTo 0 ' End error handling End If ' Get the current section index currentSection = application.ActivePresentation.Slides(currentSlide).sectionIndex If is_rename = "true" Then ' Rename the current section new_section = application.ActivePresentation.SectionProperties.Rename(currentSection, section_title) WScript.Quit ' Stop the execution of the script Else ' Get the total number of sections totalSections = application.ActivePresentation.SectionProperties.Count If totalSections = 0 Then new_section = application.ActivePresentation.SectionProperties.AddSection(currentSection, section_title) Else ' Add a new section after the current section new_section = application.ActivePresentation.SectionProperties.AddSection(currentSection + 1, section_title) End If End If