Need help on add picture into Excel via VBA


Posted by Oscar on December 10, 2000 2:06 AM

May I know how to add a fews wmf picture into certian location of Excel cell via VBA?
Thanks
regards
Oscar

Posted by Ivan Moala on December 10, 2000 2:17 AM

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 (*.wmf),*.wmf,(*.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
ActiveSheet.Pictures.Insert(Pict).Select


End Sub


Ivan


to delete ALL picture files then;

Sub DeletePicts()
Dim Pict As Object

For Each Pict In ActiveSheet.Shapes
MsgBox Pict.Name & ":" & Pict.Type
If Pict.Type = 13 Then
Pict.Delete
End If
Next
End Sub

Ivan



Posted by Oscar on December 10, 2000 2:55 AM

Re: Ivan,Thanks a lot!

Ivan,
Thanks a lot!
Regards
Oscar