PDA

View Full Version : [SOLVED:] Extract first line of notes section on each slide - how to?



TrentLane
02-14-2021, 03:33 PM
Hello everyone. I'm not a professional programmer but I have a bit of working experience with VBA. I'm working on approximately 30 PPT files totaling some 10,000 slides. I need to create several derivate PPTs based on the contents of the master PPTs.


I'm thinking that I could create VBA code that creates a derivate, separate PPT based on codes that I manually enter into the notes section of a slide. For example, on the 1st line of each slide notes section, I could have something like CODE=SIVH, where each letter after SIVH makes the slide applicable to different purposes. Then if I want to create a derivate PPT that includes all slides having a code of S, it would do so provided S is somewhere in that string (after 'Code=').


[not sure if I am using the right term, but the 'notes' section to me is that small free text area beneath each slide in PPT]


So, how do I read in the 1st line of the notes section of each slide? I'll iterate through each slide. Also, the notes section of each slide will have rich text and hyperlinks after the first line. Assume Line 1 starts with CODE= and terminates with a carriage return (however PPT stores that). I think if I can read just that first line into a string, I can use string functions after that to test for a specific Character.

Thank you
27925

John Wilson
02-15-2021, 07:46 AM
This might get you started


Sub first_note()
Dim osld As Slide
Dim strCode As String
Dim strResult As String
Dim iPos As Integer
For Each osld In ActivePresentation.Slides
If osld.NotesPage.Shapes(2).TextFrame.TextRange.Paragraphs(1) Like "CODE*" Then
strCode = osld.NotesPage.Shapes(2).TextFrame.TextRange.Paragraphs(1)
iPos = InStr(strCode, "=")
strCode = Mid(strCode, iPos + 1)
End If
strResult = strResult & strCode
Next osld
MsgBox strResult
End Sub

TrentLane
02-16-2021, 11:49 AM
This might get you started


Sub first_note()
Dim osld As Slide
Dim strCode As String
Dim strResult As String
Dim iPos As Integer
For Each osld In ActivePresentation.Slides
If osld.NotesPage.Shapes(2).TextFrame.TextRange.Paragraphs(1) Like "CODE*" Then
strCode = osld.NotesPage.Shapes(2).TextFrame.TextRange.Paragraphs(1)
iPos = InStr(strCode, "=")
strCode = Mid(strCode, iPos + 1)
End If
strResult = strResult & strCode
Next osld
MsgBox strResult
End Sub

John, thank you so much... that solved several problems for me!

With those object references I was able to find a way to "save a copy as..." which I can then manipulate?

Question: there's an Application.ActivePresentation object, but if I use the .SaveCopyAs method, I get an external file copy but how would I edit the contents of that file? All the examples I see are for an active presentation.

Specifically, how would I delete a slide in that newly created copy of the master PPT by referring to a specific slide? Is it possible to create an object for a second presentation that is not active or currently opened and exists only as a file?

Also, I assume that saving as a copy also creates new unique slide IDs?

John Wilson
02-16-2021, 12:01 PM
Not sure why you are saving as a copy but if you need to do that the only sensible way to edit that file is to use presentations.Open and then edit and save and close.

Unless you added or removed slides the IDs should not change

TrentLane
02-16-2021, 01:52 PM
Not sure why you are saving as a copy but if you need to do that the only sensible way to edit that file is to use presentations.Open and then edit and save and close.

Unless you added or removed slides the IDs should not change

I'm glad you mentioned that because I wasn't sure the best way to do it. I found the Presentations.Open method:
https://docs.microsoft.com/en-us/office/vba/api/PowerPoint.Presentations.Open

Is there some way to reference the newly opened presentation's object to delete a slide? I'm not knowledgeable of how VBA's object scoping work work in this case. I've seen other examples with references to things like Shapes(1) which looks like an array reference? I'm not even sure when to look in the documentation.

Thank you

EDIT: I think I figured it out...



Presentations.Open sFileToOpen
For Each osld In Presentations(2).Slides
Debug.Print osld.SlideID
Next osld

John Wilson
02-17-2021, 01:53 AM
I think I would set an object ref to the opened presentation


Dim openPres As Presentation
Dim osld As Slide
Set openPres = Presentations.Open(FileName)
For Each osld In openPres.Slides
' do whatever
Next osld

TrentLane
02-18-2021, 11:06 AM
Solved

macropod
02-18-2021, 01:02 PM
Cross-posted at: https://www.msofficeforums.com/powerpoint/46502-how-delete-powerpoint-slide-based-keywords-notes.html
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

TrentLane
02-18-2021, 03:48 PM
It's not cross-posted. That wasn't me.

TrentLane
02-18-2021, 03:50 PM
BUT I do have a continued question....

So now that I can extract the first line of the Notes section.... I need to be able to handle a case where there's already a CODE=XXXXX on the first line. I would need to replaced CODE=XXXXX with the new CODE=YYYYY. So far I'm reading the Notes section in its entirety.

How can I remove/replace the first line (if CODE=XXX) exists and replace just that first line with CODE=YYYY?

Thanks