Hi,
I am new to Powerpoint VBA.
What i am trying
I have 2 different files in which i would like to check if the text frame consists of similar text or not.
Brief
i want to browse 2 files from a userform and would like to check if all the text frame in file 1 are same as file 2. Given below is my code for refernce. Not able to get the text of 2nd ppt file. Please help.
Dim file_name1 As String
Dim file_path1 As String
Dim file_path2 As String
Dim file_name2 As String
Dim oSld As Slide
Dim oShp As Shape
Dim x As Long
Dim oSld2 As Slide
Dim oShp2 As Shape
Dim x2 As Long
Dim File1_text As String
Dim File2_text As String
Dim slide_num As Double
Private Sub CommandButton1_Click()
Dim dlgOpen As FileDialog
Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
PPT.Visible = True
TextBox1.Text = ""
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
If .Show = -1 Then 'user did not press cancel so display selected file
TextBox1.Text = .SelectedItems(1)
file_name1 = TextBox1.Text
file_path1 = file_name1
End If
End With
Set dlgOpen = Nothing
End Sub
Private Sub CommandButton2_Click()
Dim dlgOpen As FileDialog
Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
PPT.Visible = True
TextBox2.Text = ""
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
If .Show = -1 Then 'user did not press cancel so display selected file
TextBox2.Text = .SelectedItems(1)
file_name2 = TextBox2.Text
file_path2 = file_name2
End If
End With
Set dlgOpen = Nothing
End Sub
Sub CommandButton3_Click()
Dim dlgOpen As FileDialog
Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
slide_num = 1
PPT.Presentations.Open FileName:=file_path1
'PPT.Presentations.Open FileName:="F:\Reports\" & Business_Plan.Value & ".ppt"
PPT.Presentations.Open FileName:=file_path2
'PPT.Presentations.Open FileName:="F:\Reports\" & Business_Plan.Value & ".ppt"
With Application.Presentations(file_path1).Windows(1)
.Activate
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
For x = ****ns.Count To 1 Step -1
File1_text = oShp.TextFrame.TextRange
Call scnd_fle_fun
Next x
End With
End If 'has text
End If 'has textframe
Next oShp
slide_num = slide_num + 1
Next oSld
End With
End Sub
Sub scnd_fle_fun()
UserForm2.Hide
With Application.Presentations(file_path2).Windows(1)
.Activate
For Each oSld2 In ActivePresentation.Slides
For Each oShp2 In oSld2.Shapes
If oShp2.HasTextFrame Then
If oShp2.TextFrame.HasText Then
With oShp2.TextFrame.TextRange
For x2 = ****ns.Count To 1 Step -1
File2_text = oShp.TextFrame.TextRange
If File1_text <> File2_text Then
MsgBox "Slide number " & slide_num & "Not Matching refer text " & File1_text
End If
Next x2
End With
End If 'has text
End If 'has textframe
Next oShp2
Next oSld2
End With
End Sub