Automating Powerpoint slides from Excel

Corleone

Well-known Member
Joined
Feb 2, 2003
Messages
841
Office Version
  1. 365
Hi
I have copied the following code another Excel sheet which automatically generates a Powepoint slide for every worksheet in the file - is there a way of modifying (im assuming the bit that i have bolded below) it so that it just generates the slides for 3 of the tabs in the worksheet?
Sheet8
Sheet9
Sheet10


Thanks
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sub Copy_Excel_To_PPT()

'Dim ppt_app As New PowerPoint.Application
'Dim ppt_file As PowerPoint.Presentation
'Dim my_slide As PowerPoint.Slide


Dim PPT_App As Object
Dim ppt_file As Object
Dim my_slide As Object
Set PPT_App = CreateObject("PowerPoint.Application")

Set ppt_file = PPT_App.Presentations.Add

Dim sh As Worksheet

For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Setting" Then
Set my_slide = ppt_file.Slides.AddSlide(1, ppt_file.SlideMaster.CustomLayouts(6))

my_slide.MoveTo (ppt_file.Slides.Count)


'''''' Format Slide title
With my_slide.Shapes.Title
.TextFrame.TextRange.Text = sh.Name
.TextFrame.TextRange.Font.Color = RGB(255, 255, 255)
.Fill.BackColor.RGB = RGB(0, 128, 128)
.TextEffect.Alignment = msoTextEffectAlignmentCentered
.TextEffect.FontName = "Arial Rounded MT Bold"
.Height = 50
End With

sh.UsedRange.CopyPicture xlScreen, xlPicture
my_slide.Shapes.Paste

''''''' Resize and reposition the picture
With my_slide.Shapes(2)
.LockAspectRatio = msoCTrue
.Width = ppt_file.PageSetup.SlideWidth - 30

.top = 0
If .Height > ppt_file.PageSetup.SlideHeight Then
.Height = ppt_file.PageSetup.SlideHeight - 120
End If

.Left = 0
If .Width > ppt_file.PageSetup.SlideWidth Then
.Width = ppt_file.PageSetup.SlideWidth - 30
End If
.Left = (ppt_file.PageSetup.SlideWidth - .Width) / 2
.top = 100

End With
End If
Next

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Alternatively - Is there a way of changing it so that that it just runs against the visible worksheets?

Thanks
 
Upvote 0
To specify your sheets, try . . .

VBA Code:
Dim targetSheetNames As Variant
targetSheetNames = Array("Sheet1", "Sheet2", "Sheet3") 'change the sheet names accordingly

Dim currentSheetName As Variant
Dim currentSheet As Object

For Each currentSheetName In targetSheetNames

    Set currentSheet = ThisWorkbook.Sheets(currentSheetName)

    Set my_slide = ppt_file.Slides.AddSlide(1, ppt_file.SlideMaster.CustomLayouts(6))
    
    my_slide.MoveTo (ppt_file.Slides.Count)

    'etc
    '
    '
    
Next currentSheetName

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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