Hi experts!
I'm currently trying to get a picture from the clipboard into a comment's UserPicture via VBA.
Reason being: I want to add pictures to cell comments that are made with an external camera program, which stores a picture in the clipboard. For this I run the camera program through VBA, wait for it's return, and then want to use the clipboard image as a comment background in the cell that had originally been clicked.
This is for a sheet a colleague will use on a tablet PC to document several things at our customers' production sites. (Technical data in the table with the picture as additional info.)
I'm well versed in C# and Delphi, but haven't done too much with Excel VBA. So you can talk dev lingo with me, but anything that is deeper VBA or Excel knowledge could need a longer explanation.
I have managed this so far that I can double-click a cell (Buttons don't work because I need to know what row was clicked) and run my camera app and wait for it. At this point I'm stuck with the issue, that the UserPicture member of .Comment.Shape.Fill requires a file name as string. But I don't have a file. I don't WANT a file. I'd like to get my clipboard picture into that.
This is what I have so far:
How could I do this? (And as a side-question: How can I detect if there even is a picture in the clipboard? If the cam app is canceled, it won't store an image there.)
Many thanks in advance!
I'm currently trying to get a picture from the clipboard into a comment's UserPicture via VBA.
Reason being: I want to add pictures to cell comments that are made with an external camera program, which stores a picture in the clipboard. For this I run the camera program through VBA, wait for it's return, and then want to use the clipboard image as a comment background in the cell that had originally been clicked.
This is for a sheet a colleague will use on a tablet PC to document several things at our customers' production sites. (Technical data in the table with the picture as additional info.)
I'm well versed in C# and Delphi, but haven't done too much with Excel VBA. So you can talk dev lingo with me, but anything that is deeper VBA or Excel knowledge could need a longer explanation.
I have managed this so far that I can double-click a cell (Buttons don't work because I need to know what row was clicked) and run my camera app and wait for it. At this point I'm stuck with the issue, that the UserPicture member of .Comment.Shape.Fill requires a file name as string. But I don't have a file. I don't WANT a file. I'd like to get my clipboard picture into that.
This is what I have so far:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 30 Then
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run ThisWorkbook.Path & "\CamApp\Cam.exe", windowStyle, waitOnReturn
Dim clpbrd As MSForms.DataObject
Range(Target.Address).AddComment
Range(Target.Address).Comment.Visible = True
Range(Target.Address).Comment.Shape.Fill.UserPicture clpbrd.GetFromClipboard() ' <-- this doesn't work, obviously
End If
End Sub
How could I do this? (And as a side-question: How can I detect if there even is a picture in the clipboard? If the cam app is canceled, it won't store an image there.)
Many thanks in advance!