In PowerPoint VBA how do I select an existing table and then add a shadow

I'm really a newbie to PowerPoint. I got the code below from someone else's question on EE but I have no idea how to modify it. So her ae a few questions to start with:
How do I identify "Table 22"? I thought that 'Shapes("Table 22") ' might do it since the 's' in shapes went upper case after I typed in the line, but of course it didn't.
How do I specify the shadow color as RGB?
Why is there no OffestX?

Sub AddShadow()
Shapes("Table 22").Select
With Shapes("Table 22")
 .Type = msoShadow43
 .Blur = 3
 .ForeColor.ObjectThemeColor = msoThemeColorAccent6
 .Transparency = 0
 .OffsetY = 2.7
End With
End Sub

I'm using PPT 2010 and one of the wonderful improvements is that you can't record macros so you can't teach yourself as you go. :- )  Also, for some reason, when I create this macro and then try to re-access it to edit it, it gets deleted. How do I fix that?

Thanks,
John
LVL 1
John CarneyReliability Business Tools Analyst IIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochPowerPoint Consultant & DeveloperCommented:
The first s in Shapes goes upper case because it's a VBA reserved word but you need to be more explicit as to where Shapes can be found.  A Shape is part of the Shapes Collection which in turn is a child of a Slide in a Slides Collection, which in turn is a child of a Presentation object in the Presentations Collection.

So, to reference the table shape in slide 1 of your current (active) presentation, you would use this:

Sub mySub()
Dim oShp As Shape
Set oShp = ActivePresentation.Slides(1).Shapes("Table 22")
With oShp
 ... your code from above
End With
Set oShp = Nothing
End Sub
0
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Thanks, Jamie. I had to add the  ".Shadow" right after "With oShp" but then it worked! I have everything about right, but I'd like to learn how to create an 'msoShadow1' by setting the parameters manually, so that I can customize it if necessary. More importantly so that I can really understand what's going under the hood, so to speak.

Here are the parameters that constitute 'msoShadow1'
Transparency = 60%
Size = 100%
Blur = 4pt
Angle = 45 (degrees)
Distance = 3pt
Here's the current state of my code.
Sub AddShadow()
Dim oShp As Shape
Set oShp = ActivePresentation.Slides(1).Shapes("Table 22")
oShp.Select
With oShp.Shadow

 .Type = msoShadow1
 .ForeColor.ObjectThemeColor = msoThemeColorAccent4
 .Transparency = 0.6
 .Blur = 3
 .OffsetY = 2.7
 .OffsetX = 2.7

End With
Set oShp = Nothing
End Sub
Thanks,
John
0
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Also, can I create a button with which to call the code as I do in Excel? And with an InputBox so that the user can choose which Shape he/she wants to apply the shadow to.

Thanks,
John
0
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
OK John. Another point to note is that the numerical suffix of the msoShadow type does not correspond to the selection in the UI. That's because the new shadow types were added to the existing old blocky styles that were in PowerPoint 2003. So, if you want the first one in the Shadow gallery (Offset Diagonal Bottom Right) then that's actually msoShadow21. You also have .Shadow.Style to define internal/external shadow.

Next, you don't need to select an object to change it's properties. You might be selecting if for another reason but I thought I'd mention that because if the slide isn't in view, you'll get an error but you can still change the shape properties by referencing it without selection if it isn't in view. I also forgot to add that you don't 'have' to set a reference to the shape in order to use it so the code below reflects that.

For the activation "button". You 'can' add a proper ActiveX button to a slide but I wouldn't recommend that as it comes with lots of verbose security warning dialogs care of our friends at Microsoft.

I prefer to use any standard shape, which you have more style freedom over, and assign the click action to the macro (Insert / Action / Mouse Click / Run Macro / AddShadow). You can also pass the shape so you could do this:

Sub AddShadow(oShpTrigger As Shape)
  Dim myTime As Single, buttonText As String
  With ActivePresentation.Slides(1).Shapes("Table 22").Shadow
   .Type = msoShadow21
   .ForeColor.ObjectThemeColor = msoThemeColorAccent4
   .Transparency = 0.6
   .Blur = 3
   .OffsetY = 2.7
   .OffsetX = 2.7
  End With
  
  ' Provide the user with feedback
  buttonText = oShpTrigger.TextFrame.TextRange.Text
  oShpTrigger.TextFrame.TextRange.Text = "Done"
  myTime = Timer
  Do While Timer < myTime + 0.5: DoEvents: Loop
  oShpTrigger.TextFrame.TextRange.Text = buttonText
End Sub

Open in new window


Next, add a rectangle to your slide and set the text to "Add Shadow" and then assign the Mouse Click action to AddShadow. Run the slide show and click the shape button!

Note that this will only work in the slide show view and if you wanted to do it in the normal view you can just click Alt+F8 and run the macro or if you need the function to be more available, consider turning it into an application add-in (.ppam) with a custom ribbon tab with your own button. That way it's independent from the document.

Finally, as you have static index & named references to the slide and table, you should consider searching for the table(s), making the final code something like this:

Option Explicit

Sub AddShadow(oShpTrigger As Shape)
  Dim myTime As Single, buttonText As String
  Dim oSld As Slide, oShp As Shape
  For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
      If oShp.Type = msoTable Then
        With oShp.Shadow
         .Type = msoShadow21
         .ForeColor.ObjectThemeColor = msoThemeColorAccent4
         .Transparency = 0.6
         .Blur = 3
         .OffsetY = 2.7
         .OffsetX = 2.7
        End With
      End If
    Next
  Next
  
  ' Provide the user with feedback
  buttonText = oShpTrigger.TextFrame.TextRange.Text
  oShpTrigger.TextFrame.TextRange.Text = "Done"
  myTime = Timer
  Do While Timer < myTime + 0.5: DoEvents: Loop
  oShpTrigger.TextFrame.TextRange.Text = buttonText
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Thanks, Jamie, I think I can work with this.    ~ John
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.