Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Can anyone provide sample code for a macro to export multiple objects into a single powerpoint slide.
Looks like there are no previous discussions regarding this topic.
All the discussions only tell about pasting a single object per slide.
I would really appreciate it, if someone sheds light on this topic.
Thanks,
Bharath
Thank you for the sample. One little issue is that all objects are coming on top of each other.. Can I assign positions? Also, Is there anyway I can include all these objects into a single image instead of multiple images?
Best,
Alec
Hello alec,
To choose the position of the objects, you can use :
SET Shape = PPSlide.Shapes(PPSlide.Shapes.count) ' Select the last picture which was pasted into the slide
With Shape
.LockAspectRatio = msoTRUE 'Allow size modification
.PictureFormat.CropTop = 10 'crop
.PictureFormat.CropBottom = 10
'.PictureFormat.CropRight = 10
.left=01
.top= 77
.height= 180
.width=370
END With
I'm not sure you can export the objects in only one picture.
hey guys! how are you.
I want to create a powerpoint from some differents qlikview objects. I could creat the macro wich create the ppt and paste the objects but i have the following questions:
How can i create the ppt with a specific name?
How can i put one object per slide ?
How can i put two specific objects in a specific slide?
here i paste the macro. THANKS A LOT!!!
Sub ppt
'An array with the objects you want to export to powerpoint
Dim myArray(4)
myArray(0) = "CH09"
myArray(1) = "TX22"
myArray(2) = "TX23"
myArray(3) = "TX31"
'Create ppt object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set objPresentation = objPPT.Presentations.Add
'Apply a template if you want one
'objPresentation.ApplyTemplate _
' ("C:\mytemplate.potx")
'For each object in the array create a new slide and paste it.
For each item in myArray
' Set MySheet = ActiveDocument.GetSheet(i)
Set PPSlide = objPresentation.Slides.Add(1,11)
' ActiveDocument.ActiveSheet.CopyBitmapToClipboard
ActiveDocument.GetSheetObject("CH09").CopyBitmapToClipboard
ActiveDocument.GetSheetObject("TX22").CopyBitmapToClipboard
with PPSlide.Shapes.Paste
.Left = 90
.top = 50
.width=50
.height=90
end with
ActiveDocument.GetSheetObject("TX31").CopyBitmapToClipboard
with PPSlide.Shapes.Paste
.Left = 150
.top = 350
.width=20
.height=20
end with
ActiveDocument.GetSheetObject("TX23").CopyBitmapToClipboard
with PPSlide.Shapes.Paste
.Left = 150
.top = 350
.width=50
.height=90
end with
Next
'Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
Hi Juan,
It's been a while I haven't used macros but I will try to help you with what I remember.
1) To give a name to your ppt, you can save it at the end:
objPresentation.SaveAs "PathWhereYouwantToSaveYourPPT\YourPPTName.pptx"
2) To put one object per slide, I'd say you first have to select the slide and then paste the object you want to paste in. (and do it as many times as you have objects)
For example :
Set PPTSlide = objPresentation.Slide(1) selects (or create if none exists) the first slide of your presentation.
3) Once you have selected the slide, you can paste your 2 objects.
Hope this helps
Have a good day
Laura
Laura, thanks. I have problems with 2) and 3) because i create an array with the differents objects i want to export. i have this code:
Dim myArray(3)
myArray(0) = "CH09"
myArray(1) = "TX23"
myArray(2) = "TX31"
---------------------------------------------------
For each item in myArray
' Set MySheet = ActiveDocument.GetSheet(i)
Set PPSlide = objPresentation.Slides.Add(1,11)
' ActiveDocument.ActiveSheet.CopyBitmapToClipboard
ActiveDocument.GetSheetObject("CH09").CopyBitmapToClipboard
with PPSlide.Shapes.Paste
end with
*****************
But I would like to select the objects and then paste that on the ppt.
Thanks!
Ok, are your QV objects on the same sheet ?
As far as I know, you cannot select all your objects first and then paste them because the command : PPSlide.Shapes.Paste only takes into account the last shape.
What about using a loop ?
Something like :
for i=1 to 3
Select object(i)
Select Slide(i)
Paste
end
Do you only have 3 objects to paste or is it just for the example?
for now, yes.
Is a loop possible for you ?
Do you need to paste 1 object per sheet ? Is there a way to calculate the numero of the sheet you want to apste each object on ?
Me parece que podemos hablar en español jaja, necesito pegar un objeto en un slide especifico y en algunos casos pegar 2 objetos en otros slides en particular, la idea es crear un powerpoint con los objectos actualizados de manera automática.
Pensaba utilizar una sentencia IF en donde dependiendo el ID de Objeto, lo pegue en una Slide 5, por ejemplo. El problema es que no se como armar el codigo para que lo realice.
Saludos y gracias!!
jaja, no soy española o sudamericana. Soy francesa. Entiendo un poco el español pero el ingles es mas facil para mi
If there is no really relationship between the object and the numero of the slide, why don't you want to simply write one block of code per object ?
Sth like :
'Object 1
Set PPSlide=objPresentation.Slides(1) 'select the slide
ActiveDocument.GetSheetObject(myArray(0)).CopyBitmapToClipboard 'Copy the object you want
PPSlide.Shapes.Paste 'Paste
Then you can configure the size and position..and do it for each object.
I am not sure a loop will be more efficient if it has to go through all the powerpoint to check some conditions (IF) to paste the object or not and so on...
What do you think ?