amorales75pr
New Member
- Joined
- Sep 2, 2016
- Messages
- 7
Hi;
First I will like you to excuse me for my English cause it is not my first language. I am trying to add and image in a form so the user can click on a button and browse the computer for the image. I have add the button and a macro for temporarily unlock and lock the form and browsing for the image in the computer but because not all images are the same size, when add it some block other cells in the form.
I will like the image to be added with in a range of cells so it will always be in the same place and to have the same size always, does not matter if the are out of proportion(does not have to maintain proportion).
Thanks and this is what I have so far:
Sub Insert_Picture() Sheet1.Unprotect Password:="xxxxx"
Dim MyWidth As Double
Dim MyHeight As Double
Dim Image As Object
' Para definir la imagen
'----------------------------------------------------------
'- check for existing picture
If ActiveSheet.Pictures.Count > 0 Then
rsp = MsgBox("There is an existing picture. " & vbCr _
& "Ya hay una imagen. ¿Desea sustituirla?", vbYesNoCancel)
If rsp = vbCancel Then Exit Sub
If rsp = vbYes Then
ActiveSheet.Pictures(1).Delete
End If
End If
'-----------------------------------------------------------
'- get new picture
Application.Dialogs(xlDialogInsertPicture).Show
'- may not have inserted a picture
If ActiveSheet.Pictures.Count > 0 Then
'- resize
MyWidth = ActiveSheet.Range("b8:b25").Left
MyHeight = ActiveSheet.Range("b8:w8").Top
Selection.Top = 110
Selection.Left = 20
Selection.Width = 170
Selection.Height = 75
Else
MsgBox ("Ninguna imagen ha sido añadida.")
End If
Sheet1.Protect Password:="xxxxx"
End Sub
First I will like you to excuse me for my English cause it is not my first language. I am trying to add and image in a form so the user can click on a button and browse the computer for the image. I have add the button and a macro for temporarily unlock and lock the form and browsing for the image in the computer but because not all images are the same size, when add it some block other cells in the form.
I will like the image to be added with in a range of cells so it will always be in the same place and to have the same size always, does not matter if the are out of proportion(does not have to maintain proportion).
Thanks and this is what I have so far:
Sub Insert_Picture() Sheet1.Unprotect Password:="xxxxx"
Dim MyWidth As Double
Dim MyHeight As Double
Dim Image As Object
' Para definir la imagen
'----------------------------------------------------------
'- check for existing picture
If ActiveSheet.Pictures.Count > 0 Then
rsp = MsgBox("There is an existing picture. " & vbCr _
& "Ya hay una imagen. ¿Desea sustituirla?", vbYesNoCancel)
If rsp = vbCancel Then Exit Sub
If rsp = vbYes Then
ActiveSheet.Pictures(1).Delete
End If
End If
'-----------------------------------------------------------
'- get new picture
Application.Dialogs(xlDialogInsertPicture).Show
'- may not have inserted a picture
If ActiveSheet.Pictures.Count > 0 Then
'- resize
MyWidth = ActiveSheet.Range("b8:b25").Left
MyHeight = ActiveSheet.Range("b8:w8").Top
Selection.Top = 110
Selection.Left = 20
Selection.Width = 170
Selection.Height = 75
Else
MsgBox ("Ninguna imagen ha sido añadida.")
End If
Sheet1.Protect Password:="xxxxx"
End Sub