BabyFish2019
New Member
- Joined
- Nov 25, 2019
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
Hi
I am trying to automate a powerpoint presentation and am trying to write some basic instructions so that I can use them to tweak the code below. I want to have an excel spreadsheet that is updated centrally and then the macro will write the presentation from the sheet. I have written the basic code below but need help expanding it please. I want it to use the below table which sits on Sheet2 to populate the slides and I would like it to do the following:
on "Sheet2" in the sheet there will be a table
So based on the above I would like to create 3 slides (1 for each row in the sheet)
Column A represents what slide number is being dealt with
Column B represents the type of slide (I know this can be a number and in my below code I have used Set myslide = mypresentation.slides.Add(1, 11) where 11 is the slide type but I don't know where I can get a list of the slide types to use?) essentially if I knew the list of numbers I would want this code to replace the "11" it this example with what ever slide type number is written in column B.
Column C would label the slide title with whatever text is in that box
Column D would then fill the contents of the slide with whatever is written in that cell - is there away to use an autofit function as I have tried to use activeSlide.Shapes(2).TextFrame.TextRange.Font.Size = 10 but this doesn't work)
Column E - if there is a chart or table to be included this will be found on "Sheet1" in the relevant range. So my code below includes a table on sheet1 range A3:E12 which works but not sure how to do make it find a chart?
So basically I want the VBA to create a slide per row of information and keep going until all rows have a slide. So in this example there will be 3 rows so 3 slides but if there were 5 rows of data I would want 5 slides etc.
I am not great with VBA but understand it so if someone could show me the code I know I could manipulate it to do what I want, however I struggle to get the code to sit in the right part of the function.
I hope this makes sense and thank you in advance.
I am trying to automate a powerpoint presentation and am trying to write some basic instructions so that I can use them to tweak the code below. I want to have an excel spreadsheet that is updated centrally and then the macro will write the presentation from the sheet. I have written the basic code below but need help expanding it please. I want it to use the below table which sits on Sheet2 to populate the slides and I would like it to do the following:
on "Sheet2" in the sheet there will be a table
(A1) Slide Number | (B1) Slide Format | (C1) Slide Title | (D1) Slide Text Content | If slide has a table/chart location and range of table |
1 | Title and Content | N/A | ||
2 | Title Chart and Content | "Sheet1" (not sure how to find or name a chart) | ||
3 | Title Table and Content | "Sheet1" - range of table is A3:E12 |
So based on the above I would like to create 3 slides (1 for each row in the sheet)
Column A represents what slide number is being dealt with
Column B represents the type of slide (I know this can be a number and in my below code I have used Set myslide = mypresentation.slides.Add(1, 11) where 11 is the slide type but I don't know where I can get a list of the slide types to use?) essentially if I knew the list of numbers I would want this code to replace the "11" it this example with what ever slide type number is written in column B.
Column C would label the slide title with whatever text is in that box
Column D would then fill the contents of the slide with whatever is written in that cell - is there away to use an autofit function as I have tried to use activeSlide.Shapes(2).TextFrame.TextRange.Font.Size = 10 but this doesn't work)
Column E - if there is a chart or table to be included this will be found on "Sheet1" in the relevant range. So my code below includes a table on sheet1 range A3:E12 which works but not sure how to do make it find a chart?
So basically I want the VBA to create a slide per row of information and keep going until all rows have a slide. So in this example there will be 3 rows so 3 slides but if there were 5 rows of data I would want 5 slides etc.
I am not great with VBA but understand it so if someone could show me the code I know I could manipulate it to do what I want, however I struggle to get the code to sit in the right part of the function.
I hope this makes sense and thank you in advance.
VBA Code:
Private Sub CommandButton1_Click()
Dim r As Range
Dim powerpointapp As Object
Dim mypresentation As Object
Dim myslide As Object
Dim myshape As Object
'this is the range and location of the table you want to insert into Powerpoint
Set r = ThisWorkbook.Worksheets("Sheet1").Range("A3:e12")
On Error Resume Next
'if PowerPoint is already opened
Set powerpointapp = GetObject(Class:="PowerPoint.Application")
'if PowerPoint is not already open then this will open PowerPoint
If powerpointapp Is Nothing Then Set powerpointpp = CreateObject(Class:="PowerPoint.Application")
'This will create a new presentation
Set mypresentation = powerpointapp.presentations.Add
'the second number after the comment selects the standard slide template type from powerpoint so change based on what slide you want to create.
Set myslide = mypresentation.slides.Add(1, 11)
'"r" is what we have labelled the table range earlier and we are copying this into the presentation
r.Copy
'to paste the range into the slide - DataType number select from list below
' 0 = ppPasteBitmap
' 1 = •ppPasteDefault
' 2 = •ppPasteEnhancedMetafile
' 3 = •ppPasteHTML
' 4 = •ppPasteGIF
' 5 = •ppPasteJPG
' 6 = •ppPasteMetafilePicture
' 7 = •ppPastePNG
' 8 = •ppPasteShape
myslide.Shapes.PasteSpecial DataType:=2
'the below 3 lines show where the range should be positioned on the slide so alter the numbers to adjust distance from left and distance from top of slide
Set myshape = myslide.Shapes(myslide.Shapes.Count)
myshapes.Left = 250
myshape.Top = 150
powerpointapp.visiible = True
powerpointapp.Activate
'this code gets rid of the cutcopy mode from the clipboard
Application.CutCopyMode = False
End Sub