vba to read value from a wksheet cell

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have some code below that takes a range in Excel and copies it as a picture into Powerpoint. The bottom section of the code sizes and positions the picture on the ppt slide. How can I change the code so the value of 0.75 that is currently hard-written into the code as '.ScaleHeight 0.75, msoTrue' is taken from cell H14 in the worksheet. The value in H14 will change.
Hope you can help, many thanks.


Dim Shp As Object
Dim sld As Object
Dim eff As Object
Const msoAnimEffectFade As Long = 10
Const msoAnimTriggerWithPrevious As Long = 2
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation

Range("G20:O20").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set sld = PPPres.Slides("Yourself")
Set Shp = sld.Shapes.Paste.Item(1)

Set eff = sld.TimeLine.MainSequence.AddEffect _
(Shape:=Shp, effectid:=msoAnimEffectFade, Trigger:=msoAnimTriggerWithPrevious) 'effect details

eff.Timing.Duration = 0.5
eff.Timing.TriggerDelayTime = 0

With Shp
.LockAspectRatio = msoTrue
.ScaleHeight 0.75, msoTrue
.Left = 21
.Top = 116
.ZOrder msoSendToBack
End With

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
just change 0.75 to Range("H14")

Edit, you may need to use
Code:
CSng(Range("H14"))
if it errors
 
Last edited:
Upvote 0
I'm no expert, but what happens if you went:
.ScaleHeight (Range"H14".value), msoTrue
 
Upvote 0
Jeez! I can't believe it was that simple - I need to have a word with myself!
Thanks, have a good wkend :)
 
Upvote 0
another quick question on this one if I may...

How do I change
.Left = 21
.Top = 116

to align the picture both centre and middle?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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