PowerPoint Creative
Log In or Register to participate in PPC!
PowerPoint Creative
Log In or Register to participate in PPC!

Go down
johnr
johnr
Administrator
Administrator
Posts : 933
Join date : 2017-08-17
Location : UK
http://www.powerpointgames.uk

VBA - CAN YOU HELP!!! Empty VBA - CAN YOU HELP!!!

Wed Jul 05, 2023 10:22 am
I want to do something that I think should be really simple with VBA.

I want some boxes (3 of them in this example) to be individually clicked on Slide 1 and appear individually on Slide 2. So, in Slideshow mode, on Slide 1 you can click on (E.g.) box 1a and 1c and when and when you go to slide 2 - there they are!

Chat GPT gave me three sets of code to copy & paste, none of which worked. It then gave up completely and basically said: 'Sorry, it can't be done on PPT with VBA'. This can't be right. Can it?

Here are the three boxes with arrow links for Next and Previous slides.
https://1drv.ms/p/s!ApWzyYF91ItI3S3wjdjoELGJ6O8F?e=EeTthh

Does anyone have some code that will do this??
rusnakcreative
rusnakcreative
Administrator
Administrator
Posts : 631
Join date : 2017-08-16
https://www.rusnakcreative.com

VBA - CAN YOU HELP!!! Empty Re: VBA - CAN YOU HELP!!!

Fri Jul 07, 2023 4:55 pm
Code:
Sub CopyShape(shp As shape)
    Dim sourceSlide As Slide
    Dim targetSlide As Slide
    Dim targetshape As shape

Set sourceSlide = shp.Parent
Set targetSlide = ActivePresentation.Slides(2)

shp.Copy
targetSlide.Shapes.Paste.Select
        
        Set targetshape = targetSlide.Shapes(targetSlide.Shapes.Count)

        targetshape.Left = shp.Left
        targetshape.Top = shp.Top

End Sub

That code was 'almost' there. I changed "sourceShape" to just 'shp' inside the beginning of the subroutine, which would grab whatever attribution of the shape that was just clicked and copy that. I use this a LOT so that when I want a user to modify the exact shape they're clicking, the code knows which shape out of everything on that slide to modify instead of trying to find it through all the slide objects.

What are you trying to do with copy/paste? Another alternative could be sld.shape.visible = True OR sld.shape.visible = False (which would show or hide a shape but not copy/paste/remove anything. Using this would require you to have the same exact shapes on both slides, but would appear the same. You would also avoid having the error of having multiple shapes stacked on top of one another unless you add more code to deter that.
johnr
johnr
Administrator
Administrator
Posts : 933
Join date : 2017-08-17
Location : UK
http://www.powerpointgames.uk

VBA - CAN YOU HELP!!! Empty Re: VBA - CAN YOU HELP!!!

Sat Jul 08, 2023 11:34 am
Thanks Mike! It did work!

I've got a potential commission to produce a psychological card-sort activity for a Life Coach. There are 5 categories of cards - between 30 and 95 of them. Someone is asked to choose various cards from each category, and these are subsequently examined and worked on. 

I was looking to find a way of having the categories of cards chosen from individual slides, which then appear on the 'working slide' under each category heading. At the moment, I would see the problem you mention about stacking happening, especially in the set of 95 cards from which a number would be chosen to appear on the working slide.

What I also found with the code above was that if clicked on the target slide, the object would duplicate.

I've told the client that I'm not sure that PPT is the best way to go. It looks more like a job for an app developer. Any more thoughts welcome!
matto
matto
Featured Creator
Featured Creator
Posts : 81
Join date : 2022-08-11
Location : Japan

VBA - CAN YOU HELP!!! Empty Re: VBA - CAN YOU HELP!!!

Sun Jul 09, 2023 11:38 pm
Sorry I'm so late to the party. My solution would have been wayyyyy more unnecessarily complicated. 

Goo job rusnak!
Sponsored content

VBA - CAN YOU HELP!!! Empty Re: VBA - CAN YOU HELP!!!

Back to top
Permissions in this forum:
You cannot reply to topics in this forum