On 2002-04-17 06:55, Matty2470 wrote:
Hi,
Can anyone help me? I want to have my users click a command button to open a dialogue to browse for a photo and add it to a field in a worksheet.
Please...
Try;
<pre/>
'This routine will prompt you for the file location
'Then ask you for the Top cell location to paste to.
Sub Insert_Pict()
Dim Pict
Dim ImgFileFormat As String
Dim PictCell As Range
Dim Ans As Integer
'ActiveSheet.Protect True, True, True, True, True
ImgFileFormat = "Image Files wmf (*.gif),*.gif,(*.bmp),others , jpg (*.jpg),*.jpg"
GetPict:
Pict = Application.GetOpenFilename(ImgFileFormat)
'Note you can load in nearly file format
If Pict = False Then End
Ans = MsgBox("Open : " & Pict, vbYesNo, "Insert Picture")
If Ans = vbNo Then GoTo GetPict
'Now paste to userselected cell
GetCell:
Set PictCell = Application.InputBox("Select the cell to insert into", Type:=8)
If PictCell.Count > 1 Then MsgBox "Select ONE cell only": GoTo GetCell
PictCell.Select
'PictCell.Activate
ActiveSheet.Pictures.Insert(Pict).Select
End Sub
'to delete ALL picture files then;
Sub DeletePicts()
Dim Pict As Object
For Each Pict In ActiveSheet.Shapes
MsgBox "This is " & Pict.Name & ": Type:= " & Pict.Type
If Pict.Type = 13 Then
Pict.Delete
End If
Next
End Sub
</pre>