Macro help

P

puiuluipui

Hi, i need to modify this macro to insert a picture based on a value in cell
"A1"

Can this be done?
Thanks!


Sub Add_Picture()

'

'
Application.ScreenUpdating = False

'varible Picture1 is inserted down below - ***change both***
Picture1 =
Application.GetOpenFilename("Picture,*.JPG,Picture,*.JPEG,Picture,*.GIF,Picture,*.BMP")
'edit "("Picture,*.*")" section to add or chanve visible file types

ActiveSheet.Pictures.Insert(Picture1).Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 175
Selection.ShapeRange.Width = 234
Application.ScreenUpdating = True

End Sub
 
P

Per Jessen

Not sure how to understand 'based on value', but if A1 holds the
filename like 'MyPicture.JPG' then this should do it:

Sub Add_Picture()
Application.ScreenUpdating = False

MyPath = "C:\Temp\" ' Change to suit
PictName = Range("A1").Value
Picture1 = MyPath & PictName
ActiveSheet.Pictures.Insert(Picture1).Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 175
Selection.ShapeRange.Width = 234

Application.ScreenUpdating = True
End Sub

Regards,
Per
 
P

puiuluipui

Thanks!

"Per Jessen" a scris:
Not sure how to understand 'based on value', but if A1 holds the
filename like 'MyPicture.JPG' then this should do it:

Sub Add_Picture()
Application.ScreenUpdating = False

MyPath = "C:\Temp\" ' Change to suit
PictName = Range("A1").Value
Picture1 = MyPath & PictName
ActiveSheet.Pictures.Insert(Picture1).Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 175
Selection.ShapeRange.Width = 234

Application.ScreenUpdating = True
End Sub

Regards,
Per



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top