Exvel VBA to Powerpoint slides

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi ZVI,

I have created another thread as advised

To recap - I need to copy my ranges as picture or best quality and paste it into my PP Templat Pres

I have a PP Template which contains 2 sheets (Title sheet with a text box named TitleText) and Content Slide with a textbox named ContentText

I found some code online that does some of this but this creates a new powerpoint presentation and pastes it there. My condition is slightly diff where I need to 1st update the Titke slide text and then use the Content slide template to paste each slide in as the text and theme is pre-formatted

I then need to resize my image so it looks nice and not overlapping the slide

This is the code I found - I tried to add my bits of code attempt in there and have commented bits where I would need to change to suit me (I have left the original code that I found in there for ref)

Hopefully this will make more sense

This is the code

Code:
Sub CreatePowerPointPresentation()
Dim DasboardSh As Worksheet
Dim Weekdash As Worksheet
Dim CalcSh As Worksheet
Dim MyTitle As Range
Dim PPTitleTextRange As Range
Dim PPCopyRange As Range
Dim PowerPointApp As Object
Dim PPTemmplatePath As String
Dim TitleTextRow As Long
Dim CopyPictureRow As Long
Set DasboardSh = Worksheets("DAILY SUMMARY")
Set Weekdash = Worksheets("WEEK DASHBOARD")
Set CalcSh = Worksheets("CALCULATION")
Set MyTitle = CalcSh.Range("TITLETEXT")
Set PPTitleTextRange = CalcSh.Range("PPTITLE")
'Set PPCopyRange = CalcSh.Range("COPYRANGE")
'Create an Instance of PowerPoint
  On Error Resume Next
    
    'Is PowerPoint Template already opened?
      
      'This is where i need to open up my PP Template but is its open then set a ref to it
      'Set PowerPointApp = GetObject("PowerPoint.Application")
    
    'Clear the error between errors
      Err.Clear
    'If PowerPoint is not already open then open PowerPoint
      'This is where i need to open up my PP Template but is its open then set a ref to it
      'If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject("PowerPoint.Application")
    
    'Handle if the PowerPoint Application is not found
      If Err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
      End If
  On Error GoTo 0
'Make PowerPoint Template Visible and Active
  
  'PowerPointApp.Visible = True
  'PowerPointApp.Activate
  
'Create a New Presentation
  'Set myPresentation = PowerPointApp.Presentations.Add
'Create a copy of Slide 1 (Title Slide) to the end of the slide - i have renamed the text box to TitleText
  'Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
  
'Add the MyTitle.value to TitleText
   
'CopyRanges
For i = 2 To 11
    'SlideTitle = CalcSh.Range("U" & i)
    'Create copy of Content Slide (Slide) - i have named the text box ContextText
    'Add the text SlideTitle to ContextText
    
    'Set PPCopyRange = Weekdash.Range("V" & i)
    
    'Copy Excel Range
    'PPCopyRange.Copy
    
    'I need to Paste to this content slide and resize and position
    
    'Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
    'Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)
    
    'mySlide.Shapes.PasteSpecial DataType:=2
    
Next i
  
 
End Sub
 
Thank you do much - i will give it a go

just for my reference, why was it that i got the occasional remote server problem and why was it that the code stopped on the line when copying but when i selected the PowerPoint manually it continued to work?

Just trying to understand why that happened

Thanks
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Please see post 21 also (previous post)

Another Question - GetObject(f2) and objectpresentation.application
how does that work because its the 1st i seen that way of doing it..normally i see early or late binding.

A couple of other things I learnt from
studying your code is that if you pit the if on 1 line and use the underscore to continue the text, i dont need to close the If with an EndIf

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,316
Messages
6,124,225
Members
449,148
Latest member
sweetkt327

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