Micro Focus QTP (UFT) Forums
How to insert picture in excel cell - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to insert picture in excel cell (/Thread-How-to-insert-picture-in-excel-cell)



How to insert picture in excel cell - bangla123 - 10-21-2010

Hi,

I can take a screen shot using qtp. How can i insert the image in excel cell or range of cells?

This code below take the screenshot and works:

Code:
Dim path_error_file
path_error_file = "C:\Documents and Settings\msafiullah\Desktop\\error.bmp"
Desktop.CaptureBitmap path_error_file,True


This code in below i used to insert the picture into excel cell(or range) but it does not work.

Code:
Set Obj = CreateObject ("Excel.Application")    'Pass
Obj.Visible = True      'Pass

Set objWorkbook1 = Obj.Workbooks.Open("C:\Documents and Settings\msafiullah\Desktop\Book18.xls")     'Pass


range("B9").Select      'Pass

Obj.objWorkbook1.objWorksheet1.Pictures.Insert("C:\Documents and Settings\msafiullah\Desktop\error.bmp") 'Fail


Someone pls help me. Thanks.

Safi


RE: How to insert picture in excel cell - Saket - 10-21-2010

This should give the error at the Range("B9").select statement only.

this will work in VBA macro but you can not use this way in automation. also the the next statment, where does the objWorkSheet1 declared.
replace your code with the below and try
Code:
objWorkbook1.ActiveSheet.range("B9").Select

objWorkbook1.ActiveSheet.Pictures.Insert("C:\Documents and Settings\msafiullah\Desktop\error.bmp")



RE: How to insert picture in excel cell - bangla123 - 10-21-2010

Hi,

Thanks for your help.
It works kind of.
This code in below take a screen shot but takes too much space on excel sheet.
Code:
objWorkbook1.ActiveSheet.range("d3:f3").Select

objWorkbook1.ActiveSheet.Pictures.Insert("C:\Documents and Settings\msafiullah\Desktop\error.bmp")

I want to insert the picture only from cell D3:F3 and enlarge the picture by clicking the picture.

Thanks.

safi


RE: How to insert picture in excel cell - bangla123 - 10-26-2010

Hi,
Someone can help me how i can insert a picture to the specified range?
Even if i specify range, it insert the picture outside the range.

below code inserts the picture but taking too much space on the excel sheet. Below code should insert the picture only from d3 to f3 but instead it inserts in almost entire sheet.
Code:
objWorkbook1.ActiveSheet.range("d3:f3").Select

objWorkbook1.ActiveSheet.Pictures.Insert("C:\Documents and Settings\msafiullah\Desktop\error.bmp")

Thanks.

safi


RE: How to insert picture in excel cell - KVK - 10-26-2010

Hi,

We can not enlarge the picture by clicking on a cell. This can be done using a hyperlink.

There is a possiblities to insert an hyperlink which reffers to a path, below is the code

Code:
path_error_file = "C:\Documents and Settings\msafiullah\Desktop\\error.bmp"
nName = "ScreenShot"
Desktop.CaptureBitmap path_error_file,True

ExlFormula = "=HYPERLINK("&chr(34)&path_error_file&chr(34)&","&chr(34)&nName&chr(34)&")"
Set Excel = createobject("Excel.Application")
Set oBook = Excel.Workbooks.Open ("c:\MyExcel.xls")
oBook.ActiveSheet.cells(1,1).Formula = ExlFormula
oBook.Save
oBook.Close
-- Vinod


RE: How to insert picture in excel cell - Saket - 10-26-2010

basically you can not insert a picture in a cell, Pictures are inserted in the worksheet and it will always float. what you can do is move or resize the picture inserted


RE: How to insert picture in excel cell - bangla123 - 10-29-2010

Thanks for your help.
If I click the hyperlink(screeshot) works good in my machine. Actually, I am trying to take a screenshot of the error messages of the application and send to my manager. If I use hyperlink, I can see only the link name(screenshot) on the excel sheet. I may have 20 screenshots then 20 hyperlinks in excel. How can I send an email to my manager,the excel file and all the screenshots, so my manager can click the hyperlinks and see the screenshots?

Thanks.


RE: How to insert picture in excel cell - Saket - 10-29-2010

bundle your excel sheet and the snapshot folder together and send it