-
-
Save jpoehnelt/c25792c61ae65d67251d to your computer and use it in GitHub Desktop.
Insert image into actively selected cell's comment and remove previously selected cell's comment in a range.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public OldCell As Range | |
Private Sub Worksheet_SelectionChange(ByVal Selected As Range) | |
' Exit if more than one cell selected | |
If Selected.Cells.Count > 1 Then Exit Sub | |
' Variable Declarations | |
Dim column As Range | |
Dim path As String | |
' Path to photos | |
path = "D:\Photo Folder" | |
' Set the range from second row to last row | |
Set column = Range("B2:B" & Range("b" & Rows.Count).End(xlUp).Row) | |
' Exit if not in column | |
If Intersect(Selected, column) Is Nothing Then Exit Sub | |
' Set previous to current active cell | |
If OldCell Is Nothing Then | |
Set OldCell = Selected | |
Else | |
OldCell.Comment.Delete | |
Set OldCell = Selected | |
End If | |
For Each cell In Selected | |
With cell | |
On Error Resume Next | |
.ClearComments | |
.AddComment ("") | |
.Comment.Shape.Fill.UserPicture (strPath & "\" & cell.Value & ".jpg") | |
.Comment.Shape.Height = 200 | |
.Comment.Shape.Width = 300 | |
End With | |
Next cell | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment