Dear All,
I am using VBA to copy slide from one presentation and paste it to other presentation. Idea is to copy slide which contains value entered by the user (like country name etc). I am able to copy and paste - however, could paste using source format of the source presentation. So can any body help me to find out how to paste slide from one presentation and paste into other power point presentation using "keep source format (K)" option.
Here is the code I am using:
Dim NRow As Long ' number of slides
Dim VSNo As Long ' number of last slide
Dim VPName As String ' name of PLC name keyed-in in user form
Dim VAname As String ' name of Application name keyed-in in user form
Dim VBusName As String ' name of BUS name keyed-in in user form
VSNo = UserForm1.SNo.Value ' getting number of last slide from user form
VPName = UserForm1.PName.Value ' getting PLC name from user form
VCName = UserForm1.CName.Value ' getting Country name from user form
VAname = UserForm1.AName.Value ' getting application from user form
VBusName = UserForm1.BusName ' getting BUs name from user form
Dim pres1 As PowerPoint.Presentation, pres2 As PowerPoint.Presentation, pp As Object 'defeining two power point: Press 1: source, Press 2: destination
' here creating a new presentation which will be destination presentation
PowerPoint.Application.Presentations.Add.SaveAs "Countries.pptm", ppSaveAsDefault
ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutCustom
'checking all slides
For NRow = 1 To VSNo
On Error Resume Next
Set pp = GetObject(, "PowerPoint.Application")
If Err.Number <> 0 Then Set pp = CreateObject("PowerPoint.Application")
On Error GoTo 0
Set pres1 = PowerPoint.Application.Presentations("SelPPT - destinationF.pptm") ' this is source file
Set pres2 = PowerPoint.Application.Presentations("Countries.pptm") ' destination file
'ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppCustomLayout
' if source file contains a text , for example , country name, then
If PowerPoint.Application.Presentations("SelPPT - destinationF.pptm").Slides(NRow).Shapes(12).TextFrame.TextRange.Text Like "" & VCName & "" Then
'copy the slide that contains the name of country given in user form
pres1.Slides(NRow).Copy
'pasting the slide that contains the name of country given in user form in destination file
pres2.Slides.Paste pres2.Slides.Count + 1
End If
Next
pres2.Slides(1).Delete
pres2.Save
I am using VBA to copy slide from one presentation and paste it to other presentation. Idea is to copy slide which contains value entered by the user (like country name etc). I am able to copy and paste - however, could paste using source format of the source presentation. So can any body help me to find out how to paste slide from one presentation and paste into other power point presentation using "keep source format (K)" option.
Here is the code I am using:
Dim NRow As Long ' number of slides
Dim VSNo As Long ' number of last slide
Dim VPName As String ' name of PLC name keyed-in in user form
Dim VAname As String ' name of Application name keyed-in in user form
Dim VBusName As String ' name of BUS name keyed-in in user form
VSNo = UserForm1.SNo.Value ' getting number of last slide from user form
VPName = UserForm1.PName.Value ' getting PLC name from user form
VCName = UserForm1.CName.Value ' getting Country name from user form
VAname = UserForm1.AName.Value ' getting application from user form
VBusName = UserForm1.BusName ' getting BUs name from user form
Dim pres1 As PowerPoint.Presentation, pres2 As PowerPoint.Presentation, pp As Object 'defeining two power point: Press 1: source, Press 2: destination
' here creating a new presentation which will be destination presentation
PowerPoint.Application.Presentations.Add.SaveAs "Countries.pptm", ppSaveAsDefault
ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutCustom
'checking all slides
For NRow = 1 To VSNo
On Error Resume Next
Set pp = GetObject(, "PowerPoint.Application")
If Err.Number <> 0 Then Set pp = CreateObject("PowerPoint.Application")
On Error GoTo 0
Set pres1 = PowerPoint.Application.Presentations("SelPPT - destinationF.pptm") ' this is source file
Set pres2 = PowerPoint.Application.Presentations("Countries.pptm") ' destination file
'ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppCustomLayout
' if source file contains a text , for example , country name, then
If PowerPoint.Application.Presentations("SelPPT - destinationF.pptm").Slides(NRow).Shapes(12).TextFrame.TextRange.Text Like "" & VCName & "" Then
'copy the slide that contains the name of country given in user form
pres1.Slides(NRow).Copy
'pasting the slide that contains the name of country given in user form in destination file
pres2.Slides.Paste pres2.Slides.Count + 1
End If
Next
pres2.Slides(1).Delete
pres2.Save