Opening an ppt file using vba

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have the below code and its not opening the actaul ppt file but openiong it as Presetation 1. any suggestion as how to modify the code so that I actual open's the correct PPT file and do the need copy and paste.




VBA Code:
Sub CreatePowerPoint()
    Dim mySlide As PowerPoint.Slide
    Dim myShapeRange As PowerPoint.Shape
    
    Dim oPA As PowerPoint.Application
    Dim oPP As PowerPoint.Presentation
    Dim oPS As PowerPoint.SlideRange
    Dim strTemplate As String
    Dim rng As Range
    
    strTemplate = "C:\Viral Shah\Automation\Weekly Report\Fixed Weekly Report.pptx"    [B]' not opening this file[/B]
    
    Set oPA = New PowerPoint.Application   [B]'This is creating a new preseation and do the copy and past[/B]
    oPA.Visible = msoTrue
    'changed this line to assign the new presentation to your variable
    Set oPP = oPA.Presentations.Open(strTemplate, untitled:=msoTrue)
    
    
    'If Not oPS Is Nothing Then Set oPS = Nothing
    'If Not oPP Is Nothing Then Set oPP = Nothing
    'If Not oPA Is Nothing Then Set oPA = Nothing
    
Err_PPT:
    If Err <> 0 Then
    MsgBox Err.Description
    Err.Clear
    Resume Next
    End If
    
    Set rng = ThisWorkbook.Sheets("OLTFinal Report").Range("A1:U37")
    
    Set mySlide = oPP.Slides(2)
    rng.Copy
    'mySlide.Shapes.PasteSpecial (ppPastePicture)
    mySlide.Shapes.PasteSpecial (ppPasteBitmap)
    Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
        myShapeRange.LockAspectRatio = msoFalse
        myShapeRange.Left = 20
        myShapeRange.Top = 80
        myShapeRange.Height = 400
        myShapeRange.Width = 680
    Application.CutCopyMode = False
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I have the below code and its not opening the actaul ppt file but openiong it as Presetation 1. any suggestion as how to modify the code so that I actual open's the correct PPT file and do the need copy and paste.




VBA Code:
Sub CreatePowerPoint()
    Dim mySlide As PowerPoint.Slide
    Dim myShapeRange As PowerPoint.Shape
   
    Dim oPA As PowerPoint.Application
    Dim oPP As PowerPoint.Presentation
    Dim oPS As PowerPoint.SlideRange
    Dim strTemplate As String
    Dim rng As Range
   
    strTemplate = "C:\Viral Shah\Automation\Weekly Report\Fixed Weekly Report.pptx"    [B]' not opening this file[/B]
   
    Set oPA = New PowerPoint.Application   [B]'This is creating a new preseation and do the copy and past[/B]
    oPA.Visible = msoTrue
    'changed this line to assign the new presentation to your variable
    Set oPP = oPA.Presentations.Open(strTemplate, untitled:=msoTrue)
   
   
    'If Not oPS Is Nothing Then Set oPS = Nothing
    'If Not oPP Is Nothing Then Set oPP = Nothing
    'If Not oPA Is Nothing Then Set oPA = Nothing
   
Err_PPT:
    If Err <> 0 Then
    MsgBox Err.Description
    Err.Clear
    Resume Next
    End If
   
    Set rng = ThisWorkbook.Sheets("OLTFinal Report").Range("A1:U37")
   
    Set mySlide = oPP.Slides(2)
    rng.Copy
    'mySlide.Shapes.PasteSpecial (ppPastePicture)
    mySlide.Shapes.PasteSpecial (ppPasteBitmap)
    Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
        myShapeRange.LockAspectRatio = msoFalse
        myShapeRange.Left = 20
        myShapeRange.Top = 80
        myShapeRange.Height = 400
        myShapeRange.Width = 680
    Application.CutCopyMode = False
End Sub

Please experts share any update on the script, please.
 
Upvote 0
The Untitled argument of the Open method specifies whether the file will be untitled when opened. You've set it to msoTrue, so the file will indeed be untitled. Try the following instead...

VBA Code:
Set oPP = oPA.Presentations.Open(strTemplate)

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top