Hi all,
my troubles with excel continue sadly.
Im trying to insert a picture into the background of an Excel comment.
I can create a comment with text via:
#####################################################################
## Load excel com objects attach to file
$ExcelPath = 'C:\book1.xlsx'
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$ExcelWordBook = $Excel.Workbooks.Open($ExcelPath)
$ExcelWorkSheet = $Excel.WorkSheets.item("Sheet1")
#####################################################################
## Add a comment to Cell
$ExcelWorkSheet.Range("D2").AddComment("Autor Name: `rThis is my comment")
But trying to add the picture im failing.
using GM i thought that filling in the Value field for either of these would work
$ExcelWorkSheet.Range("D3").Comment.Shape.Fill.UserPicture | gm
$ExcelWorkSheet.Range("D3").Comment.Shape.Fill.BackGround | gm
IE:
$image = "C:\test\Pictures\Kittys\gotyou.jpg"
$ExcelWorkSheet.Range("D2").Comment.Shape.Fill.BackGround.value = $image
but im getting the same error for both:
Exception setting "value": "Cannot set the Value property for PSMemberInfo object of type "System.Management.Automation.PSMethod"."
At line:1 char:1
+ $ExcelWorkSheet.Range("D2").Comment.Shape.Fill.BackGround.value = $image
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
Apparently this will work in VB
Sub Insert_Comment_Add_Background_Picture()
'Macro to insert a comment in cell A1 and then set a picture or photo as the background for that comment
Range("A1").AddComment ("Comment text goes here.")
Range("A1").Comment.Shape.Fill.UserPicture "C:\image.jpg"
End Sub
Any suggestions?