Write images to excel

VJR

Well-Known Member
Hi BP_2018,

Irrespective of the error message the Handle data item is empty in the first screenshot in Post #12.
errorwhilerunningcode-png
Step through inside the Object from the Process (F11) and see why the Handle value of 1 is not passing from the Process to the Object.
 

lee

New Member
@VJR , when I use the code I have several questions with it. First, where should I put the code
sheet.Shapes.AddPicture (Filename:=PicturePath, LinkToFile:=0, _
SaveWithDocument:= -1, Left:=cellLeft, Top:=cellTop, Width:=-1, Height:=-1)
Is it in the initialise page or this "insert" page ?
Second, I feel confused about your judgement standard in the "success" decision.
Thanks
 

VJR

Well-Known Member
@VJR , when I use the code I have several questions with it. First, where should I put the code
sheet.Shapes.AddPicture (Filename:=PicturePath, LinkToFile:=0, _
SaveWithDocument:= -1, Left:=cellLeft, Top:=cellTop, Width:=-1, Height:=-1)
Is it in the initialise page or this "insert" page ?
Second, I feel confused about your judgement standard in the "success" decision.
Thanks
Hi lee,

Looks like you picked up the code from Post #2 and missed the entire code from Post #7 which also answers your question on where to put the code.

Do elaborate your confusion on the success decision to gain more clarity on it.
 

lee

New Member
Hi lee,

Looks like you picked up the code from Post #2 and missed the entire code from Post #7 which also answers your question on where to put the code.

Do elaborate your confusion on the success decision to gain more clarity on it.
I use the code in the post#7. What really confuses me is how to use the code in the post#2.
As for success decision , I don't know the judgement in in, which means I don't know which condition makes it go to "Yes" and which goes to "No".
 

VJR

Well-Known Member
I use the code in the post#7. What really confuses me is how to use the code in the post#2.
As for success decision , I don't know the judgement in in, which means I don't know which condition makes it go to "Yes" and which goes to "No".
The code in Post #2 is already a part of the code in Post #7, so you don't need to do anything extra.
In the code, Success is set to true at the end before "catching" any error. If the code throws an exception or an error due to something gone wrong then Success becomes false and then the decision would go to 'No' else would be yes when successful. This is the same structure of code you will find in any of the other actions on the VBO. So you won't have the doubts on how the Success output parameters are used once you take a look at any of the other similar actions. They are already there in the Output parameters of the Code stage.
 

lee

New Member
The code in Post #2 is already a part of the code in Post #7, so you don't need to do anything extra.
In the code, Success is set to true at the end before "catching" any error. If the code throws an exception or an error due to something gone wrong then Success becomes false and then the decision would go to 'No' else would be yes when successful. This is the same structure of code you will find in any of the other actions on the VBO. So you won't have the doubts on how the Success output parameters are used once you take a look at any of the other similar actions. They are already there in the Output parameters of the Code stage.
New #26
Oh, thanks. It's my mistake. I forget to see it .
Thanks a lot.
 

lee

New Member
The code in Post #2 is already a part of the code in Post #7, so you don't need to do anything extra.
In the code, Success is set to true at the end before "catching" any error. If the code throws an exception or an error due to something gone wrong then Success becomes false and then the decision would go to 'No' else would be yes when successful. This is the same structure of code you will find in any of the other actions on the VBO. So you won't have the doubts on how the Success output parameters are used once you take a look at any of the other similar actions. They are already there in the Output parameters of the Code stage.
@VJR . Could you give me an example to show how to change the width and height of the picture. I saw the information you give in the post 2, but I am new to such code, I can't understand it well
 
Last edited:

hafida

New Member
Hi afzal29,

The Source Workbook data item should not be "Book 1" but in the format FileName.xlsx.
Either it needs to be an existing file or a new file that is saved so that Blue Prism will know where to paste the image.

I have the same problem as afzal29, I have 'the given key was not present in the dictionary' error message Could you help me please?
 

Attachments

  • Capture.PNG
    41.3 KB · Views: 25
Last edited:

Neetu

New Member
Hi radhavydehig,

You will need to create a new action in the Ms Excel VBO.
Here is the Code stage for it.

Code:
Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet As Object
dim cellLeft, cellTop as integer


Try

sw = GetWorkbook(Handle, Source_Workbook)
ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)


sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet

sheet.Range(Cell_to_Paste_in).select()
Dim cell as Object = excel.ActiveCell

cellLeft = cell.Left
cellTop = cell.Top

sheet.Shapes.AddPicture (Filename:=PicturePath, LinkToFile:=0, _
        SaveWithDocument:= -1, Left:=cellLeft, Top:=cellTop, Width:=-1, Height:=-1)

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    sw = Nothing
    ss = Nothing
    dw = Nothing
    ds = Nothing
    excel = Nothing
    sheet = Nothing     
End Try


Refer to the file names for the explanation of the below attachments.
Hi VJR,
Thank you for your help . Its working for all the .png images , but i am getting the following error "System Exception : Exception from HRESULT: 0x800A03EC" when i am trying to paste .bmp images in a cell .
Thanks in advance
 

saumya sinha

New Member
Hi radhavydehig,

You will need to create a new action in the Ms Excel VBO.
Here is the Code stage for it.

Code:
Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet As Object
dim cellLeft, cellTop as integer


Try

sw = GetWorkbook(Handle, Source_Workbook)
ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)


sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet

sheet.Range(Cell_to_Paste_in).select()
Dim cell as Object = excel.ActiveCell

cellLeft = cell.Left
cellTop = cell.Top

sheet.Shapes.AddPicture (Filename:=PicturePath, LinkToFile:=0, _
        SaveWithDocument:= -1, Left:=cellLeft, Top:=cellTop, Width:=-1, Height:=-1)

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    sw = Nothing
    ss = Nothing
    dw = Nothing
    ds = Nothing
    excel = Nothing
    sheet = Nothing      
End Try


Refer to the file names for the explanation of the below attachments.


Hi VJR
I have the image copied in clipboard, is there way to paste the image without actually saving it , even saving it in a data item is fine.
 

sahil_raina_91

Active Member
Hi,
have you found solution for your problem? I have the same issue
Hi VJR
I have the image copied in clipboard, is there way to paste the image without actually saving it , even saving it in a data item is fine.

If the image is copied to clipboard, then it is only a matter of pasting the clipboard to excel.
You can simply use "Paste" OR "Paste Clipboard" action in Excel VBO
 

adrianopel

New Member
If the image is copied to clipboard, then it is only a matter of pasting the clipboard to excel.
You can simply use "Paste" OR "Paste Clipboard" action in Excel VBO
I seems I have old version without "Paste" and "Paste Clipboard" actions. Where can I find new one? Thank you
 

sahil_raina_91

Active Member
I seems I have old version without "Paste" and "Paste Clipboard" actions. Where can I find new one? Thank you

You can create a new action in Excel VBO.

Create 3 Input Data Items for Code stage : Handle(number) , Workbook(text) , Worksheet(text)
Create 2 Output Data Items for Code stage : Success(flag) , Message(text)
Paste this code inside code stage :


Dim ws As Object
Try
ws = GetWorkSheet(Handle, Workbook, Worksheet)
ws.Paste()
Success = True
Catch e As Exception
Success = False
Message = e.Message
Finally
ws = Nothing
End Try
 

saumya sinha

New Member
If the image is copied to clipboard, then it is only a matter of pasting the clipboard to excel.
You can simply use "Paste" OR "Paste Clipboard" action in Excel VBO
the reason i wanted this code was coz i need to resize the image and then paste it to a particular cell in excel
 

adrianopel

New Member
You can create a new action in Excel VBO.

Create 3 Input Data Items for Code stage : Handle(number) , Workbook(text) , Worksheet(text)
Create 2 Output Data Items for Code stage : Success(flag) , Message(text)
Paste this code inside code stage :


Dim ws As Object
Try
ws = GetWorkSheet(Handle, Workbook, Worksheet)
ws.Paste()
Success = True
Catch e As Exception
Success = False
Message = e.Message
Finally
ws = Nothing
End Try

Thank you. I created action based on your instruction but when I use it I get "The given key was not present in the dictionary". Do you maybe know how to fix it?

EDIT: Issue fixed. I have used different object for creating instance (unmodified) and separate modified with your action. When I linked all process stages to the second one (modified) it works. Thank you once again.
 
Last edited:
Top