bluue s
asked on
To have macro to list down the titles of each slides in the ppt and out these list in a new slide at the end of the ppt
To have macro to list down the titles of each slides in the ppt with option to start with a slide number to end with a slide number.
Meaning if there are 60 slides:
Slide 1 = the cover page
Slide 2 = Content Page
Slide 3 = Title 1
Slide 4 = Title 2
Slide 5 = Title 5
and so on
...
...
Thus macro will run and ask: "Starting Slide No" and I input 3 (OK | Cancel)
"Ending Slide No" and I input 55
The result would be to list out the titles from Slide 3 to Slide 55 and output these titles in the same sequence in the last slide.
If no cancel, then do nothing.
The idea is to get a list of all the titles and then try to see what was missed out etc and then use it to re-organise into a content slide.
Meaning if there are 60 slides:
Slide 1 = the cover page
Slide 2 = Content Page
Slide 3 = Title 1
Slide 4 = Title 2
Slide 5 = Title 5
and so on
...
...
Thus macro will run and ask: "Starting Slide No" and I input 3 (OK | Cancel)
"Ending Slide No" and I input 55
The result would be to list out the titles from Slide 3 to Slide 55 and output these titles in the same sequence in the last slide.
If no cancel, then do nothing.
The idea is to get a list of all the titles and then try to see what was missed out etc and then use it to re-organise into a content slide.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@John Korchok
there is an error :
Compile Error : Variable not defined
For X= The X is highlighted in blue and then Sub getTitles() is highlighted yellow.
@John Wilson
How to output the "Titles.txt" to a designation folder C:\temp\ppt titles.txt
@Kesavan Jeganarayanan
thanks, the question is the same as what i have asked to John Wilson.
there is an error :
Compile Error : Variable not defined
For X= The X is highlighted in blue and then Sub getTitles() is highlighted yellow.
@John Wilson
How to output the "Titles.txt" to a designation folder C:\temp\ppt titles.txt
@Kesavan Jeganarayanan
thanks, the question is the same as what i have asked to John Wilson.
If you use the code as I posted it, it works, I always test before I put code online.
If you're going to innovate on your own and add Option Explicit before the VBA, then you will indeed have to declare X as a variable by adding:
If you're going to innovate on your own and add Option Explicit before the VBA, then you will indeed have to declare X as a variable by adding:
Dim X as Integer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@John Korchok: Thanks it works. Is it possible to also have a question to ask "Ending Slide Number?" , and if ending slide number is blank then just assume all the subsequent slides after the start slide number. And if press cancel, then just do nothing.
@John Wilson: Thanks it works. Is it possible that if ending slide number is blank then just assume all the subsequent slides after the start slide number. And if press cancel, then just do nothing.
@John Wilson: Thanks it works. Is it possible that if ending slide number is blank then just assume all the subsequent slides after the start slide number. And if press cancel, then just do nothing.
I have a couple of suggestions for the original poster to get more and better answers:
- When someone answers your question with a solution that exactly matches the original criteria, mark it as the answer.
- When you want to revise your criteria, start a new question. Tacking on extra specs after the original is answered is not good form.
E.g. using the given approaches so far:
Option Explicit
Public Sub Run()
Const MAX_SLIDES As Long = 999
Dim FileName As String
Dim FromSlide As Long
Dim ToSlide As Long
Dim Titles As String
FileName = Environ("USERPROFILE") & "\Desktop\Titles.txt"
FromSlide = InputBox("Starting Slide Number?")
ToSlide = InputBox("Ending Slide Number?", , MAX_SLIDES)
Titles = SlideTitles(FromSlide, ToSlide)
CreateTitlesSlide Titles
WriteUnicodeFile FileName, Titles
Shell "Notepad.exe " & FileName, vbNormalFocus
End Sub
Private Sub CreateTitlesSlide(ByVal CTitles As String)
Dim TitleSlide As PowerPoint.Slide
Dim PlaceholderShape As PowerPoint.Shape
Set TitleSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutObject)
TitleSlide.Shapes.Title.TextFrame.TextRange.Text = "Index"
For Each PlaceholderShape In TitleSlide.Shapes
If PlaceholderShape.PlaceholderFormat.Type = ppPlaceholderObject Then
PlaceholderShape.TextFrame.TextRange.Text = CTitles
End If
Next PlaceholderShape
Set PlaceholderShape = Nothing
Set TitleSlide = Nothing
End Sub
Private Function SlideTitles(ByVal CFromSlide As Long, ByVal CToSlide As Long) As String
Dim CurrentSlide As PowerPoint.Slide
Dim FromSlide As Long
Dim SlideNumber As Long
Dim ToSlide As Long
Dim Result As String
ToSlide = ActivePresentation.Slides.Count
If CToSlide < ToSlide Then
ToSlide = CToSlide
End If
FromSlide = CFromSlide
If FromSlide < 0 Then
FromSlide = 1
End If
If FromSlide > ToSlide Then
FromSlide = ToSlide
End If
Result = "No titles."
For SlideNumber = FromSlide To ToSlide
Set CurrentSlide = ActivePresentation.Slides(SlideNumber)
If CurrentSlide.Shapes.HasTitle Then
If CurrentSlide.Shapes.Title.TextFrame.HasText Then
Result = Result & "Slide " & CurrentSlide.SlideIndex & ": " & CurrentSlide.Shapes.Title.TextFrame.TextRange & vbCrLf
Else
Result = Result & "Slide " & CurrentSlide.SlideIndex & ": No title text" & vbCrLf
End If
Else
Result = Result & "Slide " & CurrentSlide.SlideIndex & ": No title" & vbCrLf
End If
Set CurrentSlide = Nothing
Next SlideNumber
SlideTitles = Result
End Function
Private Sub WriteUnicodeFile(AFileName As String, AContent As String)
On Local Error GoTo LocalError
Dim fileStream As Object ' ADODB.Stream
Set fileStream = CreateObject("ADODB.Stream")
fileStream.Type = 2
fileStream.Charset = "utf-8"
fileStream.Open
fileStream.WriteText AContent
fileStream.SaveToFile AFileName, 2
fileStream.Close
Set fileStream = Nothing
Exit Sub
LocalError:
Debug.Print "WriteUnicodeFile(): ERROR " & Err.Number & " - " & Err.Description
End Sub
ASKER
@John Korchok:
See my initial question:
See my initial question:
Thus macro will run and ask: "Starting Slide No" and I input 3 (OK | Cancel)
"Ending Slide No" and I input 55
The result would be to list out the titles from Slide 3 to Slide 55 and output these titles in the same sequence in the last slide.
If no cancel, then do nothing.
Your revised question would require rewriting the macro using a UserForm and placing modified code in the OK button of the form.
Hi Bluue
Please refer this link: It creates a text file with slide named data with slide titles and slide number.
https://answers.microsoft.com/en-us/msoffice/forum/all/how-can-i-generate-a-list-of-the-slide-titles-in/e99e5a8a-40a5-4bcc-bc47-65bcce57f47a