cell.Comment.ShapeRange...
"런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류"라는 오류가 발생합니다 . 뭐가 문제야?
Cells(cell.Row, 6)
이미지의 URL이 포함된 참조 열입니다. 예:http://somelink.com/img.jpg
Sub test()
Dim rng As Range
Set rng = Range("B2:B2331")
For Each cell In rng.Cells
cell.AddComment
cell.Comment.Text Text:="Owner:" & Chr(10) & ""
cell.Comment.ShapeRange.Fill.UserPicture Cells(cell.Row, 6).Value
Next
End Sub
답변1
첫째, .shaperange
의 속성이나 메서드가 아니므 comment
로 사용할 수 없습니다.
다음은 작동하는 예입니다.
Sub tete()
Dim rng As Range
Set rng = ActiveSheet.Cells(5, 6)
rng.AddComment
rng.Comment.Text Text:="hi"
rng.Comment.Shape.Fill.UserPicture ("C:\Users\path\to\pic.jpg")
End Sub
이를 사용하려면 .UserPicture()
경로를 문자열로 사용해야 합니다. 따라서 경로가 해당 셀에 있는 경우 그 값을 취하고 있는지 확인하세요.
따라서 셀 G1 =C:\Users\path\to\pic.jpg
rng.Comment.Shape.Fill.UserPicture (Range("G1"))
작동 할 것이다.
이것은 님의 편집입니다.히스토리 스탬프답변의 원래 의도를 변경하지 않고 이에 크게 기반을 두기 때문에 너무 잘 수행되지 않거나 새로운 답변으로 가시성이 없기 때문에 허용합니다.
이 버전은 Excel 2011이 설치된 macOS 10.10.5에서 작동했습니다.
Sub tete()
' Raystafarian
' https://superuser.com/a/1011255/2638314
' This is the shortest code I have seen for inserting a picture into
' a commnet. & It works.
Dim rng As Range
Dim aPicture As String
Debug.Print "-------------------------- " & Now
aPicture = "Macintosh SSD:Users:mac:Desktop:numbers:1.png"
Set rng = ActiveSheet.Cells(5, 8)
rng.AddComment
rng.Comment.Text Text:=" "
Debug.Print aPicture
rng.Comment.Shape.Fill.UserPicture (aPicture)
End Sub