Excel to Powerpoint VBA?

cdhoughton

Board Regular
Joined
Dec 5, 2003
Messages
170
Hi all

I have a Powerpoint presentation with a number of linked OLE tables that feed through from Excel data tables.

I want to use VBA to do the following:

1. Create a new copy of the *.PPT with a specified name
2. Use VBA to update the links in the *.PPT to that of the source workbook (at present the PPT links to a master spreadsheet but when this is copied, I want the copy PPT to update the links to the copy XLS)

Does anyone know if this is possible and if so a starting point for me to do this?

Cheers in advance

Chris
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Basically you need the following variables:

LinkPath (string) - set this to the path of the Excel sheet you want to link the PPT to

OLE1 - OLEx - set these to the cell ranges in the sheets you are linking to Powerpoint e.g.

Code:
OLE1 = "!Front!R1C1"
OLE2 = "!Front!R3C1"
OLE3 = "!P&L!R3C2:R20C6"
OLE4 = "!BS!R3C2:R22C6"
OLE5 = "!Front!R2C1"
OLE6 = "!CF!R4C2:R16C5"

You then need to get the Id of each OLE object in Powerpoint - the easiest way to do this is to run a loop using Powerpoint VBA to display a message box that runs in order of all the OLE objects.

Then in Excel VBA, adapt the following code:

Code:
'Open PPT
Set PPA = CreateObject("Powerpoint.Application")
PPA.Visible = True
PPA.Presentations.Open Dest 'Set Dest to path of PPT

For Each sld In PPA.ActivePresentation.Slides
    For Each sh In sld.Shapes
        
        If sh.Type = msoLinkedOLEObject Then
            If sh.OLEFormat.progID = "Excel.Sheet.8" Then
                
                Select Case sh.ID
                Case 28678
                    sh.LinkFormat.SourceFullName = LinkPath & OLE1
                Case 28680
                    sh.LinkFormat.SourceFullName = LinkPath & OLE2
                Case 28681
                    sh.LinkFormat.SourceFullName = LinkPath & OLE3
                Case 36951
                    sh.LinkFormat.SourceFullName = LinkPath & OLE4
                Case 43125
                    sh.LinkFormat.SourceFullName = LinkPath & OLE5
                Case 49272
                    sh.LinkFormat.SourceFullName = LinkPath & OLE6
                End Select
                
            Else
                
            End If
        End If
    Next
Next
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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