Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to insert picture in excel cell
#1
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#2
Solved: 11 Years, 4 Months, 4 Weeks ago
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")

Reply
#3
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#4
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#5
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#6
Solved: 11 Years, 4 Months, 4 Weeks ago
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

Reply
#7
Solved: 11 Years, 4 Months, 4 Weeks ago
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.
Reply
#8
Solved: 11 Years, 4 Months, 4 Weeks ago
bundle your excel sheet and the snapshot folder together and send it

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add picture to Excel From UFT eiko 0 1,967 02-10-2018, 12:39 AM
Last Post: eiko
  How import final calculated values by cell formula from Excel not the formula itself. qtped 1 4,898 01-17-2017, 04:05 PM
Last Post: sagar.raythatha
  Unable to insert data into datatable Prashanth 1 3,654 05-10-2013, 03:07 PM
Last Post: Saket
  insert call to new action bistritapcv 1 2,608 04-06-2013, 12:09 PM
Last Post: ravi.gajul
  how to insert error msg in a datatable using Dp? zakshah.12 0 2,041 03-05-2013, 07:49 AM
Last Post: zakshah.12

Forum Jump:


Users browsing this thread: 6 Guest(s)