Hi,
I hope you are well and safe.
I want to create a powerpoint summary based on text color (255,0,0), the VBA code will loop through all the slides and search text (including tables, shapes etc) and export it in Excel.
Here an idea of Excel's report :
| Slide # | Found text in RED | Hyperlink |
I googled my queries and found some useful codes:
Sub ExportTextToCSV()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
Dim sTempString As String
Dim PathSep As String
Dim Quote As String
Dim Comma As String
iFile = FreeFile 'Get a free file number
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Quote = Chr$(34)
Comma = ","
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
'Open output file
' NOTE: errors here if original PPT file hasn't been saved
Open oPres.Path & PathSep & "AllText.CSV" For Output As iFile
For Each oSld In oSlides 'Loop thru each slide
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
sTempString = sTempString & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma
End If
Next oShp
' print the result to file:
Print #iFile, sTempString
sTempString = ""
Next oSld
'Close output file
Close #iFile
End Sub
Based on that code I adapt it to my query :
Sub Ex_blue()
Dim iFile As Integer
Dim sTempString As String
Dim PathSep As String
Dim Quote As String
Dim Comma As String
iFile = FreeFile
PathSep = "/"
Quote = Chr$(34)
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
Dim oSld As Slide
Dim oShp As Shape
Dim i As String
Open oPres.Path & PathSep & "Export.csv" For Output As iFile
' ActiveWindow.Selection.TextRange.Font.Color = RGB(255, 0, 0)
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
With oShp.TextFrame.TextRange
If oShp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then sTempString = sTempString & Quote & oShp.TextFrame.TextRange & Quote
Print #iFile, sTempString
sTempString = ""
End With
End If
End If
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
With oShp.TextFrame.TextRange
If oShp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then sTempString = sTempString & Quote & oShp.TextFrame.TextRange & Quote
Print #iFile, sTempString
sTempString = ""
End With
End If
End If
Next oShp
Next oSld
Close #iFile
End Sub
But here are the points:- The code does not extract all the text in red; and I dont understand why
- When I do a array to export slide number and hyperlink, this is not "working" maybe .csv file is not appropriate?
If anybody could help me with that, this will be great!
Bookmarks