Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clipboard and excel 1

Status
Not open for further replies.

cimd

Programmer
Jul 18, 2001
52
0
0
ES
Hi!

I'm trying to copy an image from a picturebox to a cell in Excel.

I use the clipboard to copy it to memory (no problems there), but, when I try to paste it, it says Error in '_Default' method in 'Range' object (-2147418113 error code).

And that error code is related to ImageList control Add method (??)

Can anyone help me?

Thanks
 
This is the code:

'Loads the picture
Picture1.Picture = LoadPicture("C:\sign\AdGeneral.bmp")
'Copy to clipboard
Clipboard.SetData Picture1.Picture
'Paste to excel
Hoja.Cells(6, 13) = Clipboard.GetData(vbCFBitmap)
 
Try adding a Clipboard.Clear just before doing the Clipboard.SetData
 
cimd,

This code works for me. It does not employ neither picture control nor clipboard object; it sets picture atop of "D7" cell:

Private Sub cmdPutPicInExcel_Click()

Dim objExcel As Excel.Application

Set objExcel = CreateObject("Excel.Application")

With objExcel
.Workbooks.Add "C:\myExcel.xls"
.ActiveWorkbook.ActiveSheet.Range("D7").Select
.ActiveWorkbook.ActiveSheet.Pictures.Insert "C:\sign\AdGeneral.bmp"
.Visible = True
End With

Set objExcel = Nothing

End Sub
 
Thanks vladk. It works perfectly.
Do you know how can I add more than 1 to a cell?
 
cimd,

This example adds more than 1 image to a cell. The 2 BMPs I used were small enaugh to fit the default size of a cell.

Private Sub cmdPutPicInExcel_Click()

Dim objExcel As Excel.Application

Set objExcel = CreateObject("Excel.Application")

With objExcel
.Workbooks.Add "C:\myExcel.xls"

With .ActiveWorkbook.ActiveSheet
.Range("D7").Select
.Pictures.Insert "C:\sign\AdGeneral.bmp .Shapes("Picture 1").Select
End With

.Selection.ShapeRange.IncrementLeft 28.2

With .ActiveWorkbook.ActiveSheet
.Range("D7").Select
.Pictures.Insert "C:\sign\AdAnotherGeneral.bmp"
End With

.Visible = True
End With

Set objExcel = Nothing

End Sub

Thank you for the praise.

Vladk
 
UA!!!

amazing!!
Thanks again!!
 
just out of curiosity...

did you try this:
Code:
[COLOR=green]'Loads the picture[/color]
Picture1.Picture = LoadPicture("C:\sign\AdGeneral.bmp")
[COLOR=green]'Copy to clipboard[/color]
Clipboard.SetData Picture1.Picture
[COLOR=green]'Paste to excel[/color]
Hoja.Cells(6, 13)[COLOR=red][b].Select
Hoja.ActiveSheet.Paste[/b][/color]

I assume Hoja is your xlApp... ?

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top