+ Reply to Thread
Results 1 to 2 of 2

Modify macro to look at active powerpoint

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-06-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    191

    Modify macro to look at active powerpoint

    Hi All,

    I have a workbook that is shared by other users, so rather than having the file path follow my local I'd like to just modify it to look at whatever the active PowerPoint presentation is. Please see my code below:

    Option Explicit
    
    Sub MakePowerpoint()
    Dim MyPath As String
    Dim FileName As String
    
    Dim objPPT As Object
    Dim ppt As Object
    Dim sld As Object
    Dim shp As Object
    Dim PPName As String
    Dim shpIndex As Long
    Dim CurSlide As Long
    
    Dim sh As Excel.Worksheet
    Dim ObjName As String
    Dim ObjType As String
    Dim PPSldNum As Long
    Dim PPObjName As Long
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim MyHeight As Double
    Dim MyWidth As Double
    Dim cl As Range
    
    
    MyPath = ThisWorkbook.Path
    PPName = "CURRENT LOCAL FILE PATH"
    
    ' Open the PowerPoint Presentation
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True
    objPPT.presentations.Open PPName
    
    Set ppt = objPPT.ActivePresentation
    Set sld = ppt.slides(1)
    
    ' Add objects
    For Each cl In Range("Table_Objects[Excel Page]")
        Set sh = Sheets(cl.Value)           ' Excel Sheet
        ObjName = cl.Offset(0, 1).Value     ' Name of the thing to copy
        ObjType = cl.Offset(0, 2).Value     ' Type of the thing to copy
        PPSldNum = cl.Offset(0, 3).Value    ' PowerPoint slide number
        MyTop = cl.Offset(0, 5).Value       ' Top
        MyLeft = cl.Offset(0, 6).Value      ' Left
        MyHeight = cl.Offset(0, 7).Value    ' Height
        MyWidth = cl.Offset(0, 8).Value     ' Width
        
        Set sld = ppt.slides(PPSldNum)      ' Active Slide
        If ObjType = "Chart" Then
            sh.Shapes(ObjName).Copy
        Else
            sh.Range(ObjName).CopyPicture
            
        End If
        sld.Shapes.Paste
    
        shpIndex = sld.Shapes.Count
        With sld.Shapes(shpIndex)
            .LockAspectRatio = msoFalse
            .Top = 72 * MyTop
            .Left = 72 * MyLeft
            .Height = 72 * MyHeight
            .Width = 72 * MyWidth
            .ZOrder msoSendToBack
        End With
        
          
         
    Next
    
    End Sub

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Modify macro to look at active powerpoint

    Hi,

    You can use Getobject rather than CreateObject.

    Set objPPT = GetObject(, "PowerPoint.Application")
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Please help me to fix the code to copy picture from active worksheet into the powerpoint
    By dirtmankx65 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2016, 10:19 AM
  2. Macro with reference to active chart on active sheet
    By bhavikpatel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2014, 10:43 AM
  3. Highlight Active Row macro, and Bold the Active Cell
    By StudentTeacher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2013, 07:43 PM
  4. Macro to Print active sheet as PDF to Active workbook and customize name
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 08:52 PM
  5. Chart to PowerPoint, enhanced Metadata and active container
    By elfvis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2011, 09:38 PM
  6. Macro to edit active chart on active worksheet
    By shlurpee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2011, 04:58 AM
  7. Modify the last active row
    By Janet H in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1