Old notes/comment box macro not working after MS 365 upgrade

MrzSanchez

New Member
Joined
Feb 13, 2017
Messages
5
Office Version
  1. 365
Platform
  1. Windows
For years I've used the same code to insert pictures into cell comment boxes so that the image will pop-up when curser is over that particular cell. We were updated to Microsoft 365 and now it's inserting blank images.

VBA Code:
Sub PictureIntoComment()
'Inserts picture into cell comment. 
'(1) Paste a picture/image anywhere in the active sheet,
'(2) click on the cell where you want picture inserted, 
'(3) click on the picture and 
'(4) run macro.

Dim ch As ChartObject
Dim dWidth As Double
Dim dHeight As Double
Dim ws As Worksheet
Dim sName As String
Dim cmt As Comment
Dim sPath As String
Dim sFile As String
Dim rng As Range

Set ws = ActiveSheet
Set rng = ActiveCell
sPath = ThisWorkbook.Path & "\"
sName = ""
If sName = "" Then sName = "Picture_" & Format(Date, "ddmmyy")
sFile = sPath & sName & ".jpg"
    dWidth = Selection.Width
    dHeight = Selection.Height
    
    Selection.Cut
    Set ch = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, _
      Width:=dWidth, Height:=dHeight)
    ch.Chart.Paste
    rng.Activate
    ch.Chart.Export sFile
    ch.Delete
    
    Set cmt = rng.AddComment
    cmt.Text Text:=""
    With cmt.Shape
      .Fill.UserPicture sFile
      Kill sFile
      .Width = dWidth
      .Height = dHeight
    End With

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The only way I could get it to work consistently is to add "both" of these after the Set ch = line.

VBA Code:
    ch.Parent.Activate
    ch.Activate
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,171
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top