Extraer texto de PowerPoint

Extraer texto de PowerPoint

Entonces, encontré este bonito script aquí: http://www.pptfaq.com/FAQ00274_Export_Text_to_a_text_file-_extract_text_from_PowerPoint_-Mac_or_PC-.htm (Estoy usando el segundo)

La parte de importación es esta:

 For Each oShp In oSld.Shapes                'Loop thru each shape on slide
      'Check to see if shape has a text frame and text
      If oShp.HasTextFrame And oShp.TextFrame.HasText Then
        If oShp.Type = msoPlaceholder Then
            Select Case oShp.PlaceholderFormat.Type
                Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                    Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderBody
                    Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderSubtitle
                    Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
                Case Else
                    Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
            End Select
        Else
            Print #iFile, vbTab & oShp.TextFrame.TextRange
        End If  ' msoPlaceholder
      Else  ' it doesn't have a textframe - it might be a group that contains text so:
        If oShp.Type = msoGroup Then
            sTempString = TextFromGroupShape(oShp)
            If Len(sTempString) > 0 Then
                Print #iFile, sTempString
            End If
        End If
      End If    ' Has text frame/Has text

    Next oShp

Ya lo modifiqué un poco, por lo que el archivo de salida no contiene "Título", "Otro marcador de posición" ni ese tipo de texto, ni inserta pestañas ("vbTab"). Sin embargo, coloca cada línea (o párrafo) en una nueva línea en el archivo de salida.

La pregunta:¿Cómo puedo decirle al script que descargue todo el 'contenido' de una 'diapositiva'/'cuerpo' en la misma línea/celda?

Me di cuenta de que este script (y ni estehttp://www.pptfaq.com/FAQ00332_Export_Slide_Number_and_Title_Text_to_a_text_file.htm) muestra este comportamiento para los títulos, sólo para "body" o "ppPlaceholderBody".

No tengo idea de por qué es así o cuál es la diferencia. ¿Puede simplemente no distinguir la diferencia entre dos líneas o boletines incluso en la misma forma/cuadro? Mi objetivo es tener una numeración de líneas/celdas consistente en varios .ppts para que una línea agregada en la diapositiva 2 no haga que el contenido de la diapositiva 5 se desplace a la siguiente línea.

¡Gracias por su ayuda!

Respuesta1

Mi instalación de PowerPoint no funciona en este momento, por lo que no se ha probado. Pero...

Solo necesita crear una variable de cadena y agregarle, luego, cuando haya terminado con la diapositiva, copie esa cadena en una celda de Excel.

Dim slideText As String
For Each oShp In oSld.Shapes                 'Loop thru each shape on slide
    If Len(slideText) > 0 Then
        '--- strip the unneeded trailing CRLF
        slideText = Left$(slideText, Len(slideText) - 2)
        '--- now copy the string to the appropriate cell in Excel
    Else
        '--- clear the string for the next slide
        slideText = vbNullString
    End If

    'Check to see if shape has a text frame and text
    If oShp.HasTextFrame Then
        If oShp.TextFrame.HasText Then
            If oShp.Type = msoPlaceholder Then
                Select Case oShp.PlaceholderFormat.Type
                    Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                        slideText = slideText & "Title:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Is = ppPlaceholderBody
                        slideText = slideText & "Body:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Is = ppPlaceholderSubtitle
                        slideText = slideText & "SubTitle:" & vbTab & _
                                    oShp.TextFrame.TextRange & vbCrLf
                    Case Else
                        slideText = slideText & "Other Placeholder:" & _
                                    vbTab & oShp.TextFrame.TextRange & vbCrLf
                End Select
            Else
                slideText = slideText & vbTab & oShp.TextFrame.TextRange
            End If                           ' msoPlaceholder
        End If
    Else
        ' it doesn't have a textframe - it might be a group that contains text so:
        If oShp.Type = msoGroup Then
            sTempString = TextFromGroupShape(oShp)
            If Len(sTempString) > 0 Then
                slideText = slideText & sTempString & vbCrLf
            End If
        End If
    End If                                   ' Has text frame/Has text
Next oShp

'--- catch the text on the last slide here
If Len(slideText) > 0 Then
    '--- strip the unneeded trailing CRLF
    slideText = Left$(slideText, Len(slideText) - 2)
    '--- now copy the string to the appropriate cell in Excel
End If

Por supuesto, estás haciendo este bucle para cada diapositiva.

Respuesta2

No creo que esto ayude, pero esto:https://stackoverflow.com/questions/45468824/printing-from-ppt-vba-to-an-excel-spreadsheet intenta algo similar usando Lbound y Ubound para imprimir en celdas específicas.

Mientras las celdas permanezcan consistentes en múltiples ppt/xls, realmente no sé adónde van las cadenas...

(Aunque también selecciona un archivo xls específico, aunque quiero crear uno nuevo para cada impresión, eso no debería ser un problema con el código que ya tengo, que crea un archivo específico o usa el nombre de archivo del ppt. )

información relacionada