ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro help (https://www.excelbanter.com/excel-discussion-misc-queries/263872-macro-help.html)

puiuluipui

Macro help
 
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


Per Jessen[_2_]

Macro help
 
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

On 16 Maj, 12:58, puiuluipui
wrote:
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,Pic*ture,*.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



puiuluipui

Macro help
 
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

On 16 Maj, 12:58, puiuluipui
wrote:
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,PicĀ*ture,*.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


.



All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com