Consulting

Results 1 to 10 of 10

Thread: Extract first line of notes section on each slide - how to?

  1. #1

    Lightbulb Extract first line of notes section on each slide - how to?

    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
    notes section.jpg

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,963
    Location
    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 Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Quote Originally Posted by John Wilson View Post
    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?

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,963
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    Quote Originally Posted by John Wilson View Post
    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/off...entations.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
    Last edited by TrentLane; 02-16-2021 at 04:14 PM. Reason: figured out part of it

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,963
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7

    [SOLVED]

    Solved

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,285
    Location
    Cross-posted at: https://www.msofficeforums.com/power...rds-notes.html
    Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    It's not cross-posted. That wasn't me.

  10. #10
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •