VBA - setting uniform size of comment boxes w/ images

tommyw

New Member
Joined
Sep 28, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with a bunch of notes that have images appear when you hover over the cell. A bunch of them are getting cut off for some reason and I want to use a macro to set all of them to the same size, something like 5.0" height and 9.1" width. I've tried using other macros I've searched for but they only seem to work for text notes and mine don't have any text. LMK if you can help or if you need more details. Thank you for reading!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Place this in the Sheet code module of the Sheet the Notes are in.
VBA Code:
Sub Macro2()
Dim wb As Workbook, nt As Shape, ws As Worksheet, shps(), i As Integer
Set wb = Workbooks("Book1"): Set ws = wb.Sheets(2)
ReDim shps(ws.Shapes.Count)
i = 0
For Each nt In ws.Shapes
    Set shps(i) = nt
    shps(i).Width = 3
    i = i + 1
Next nt
End Sub
 
Upvote 0
Do I need to edit anything in the code first? I tried to run it but nothing changed.
 
Upvote 0
Sorry, I copied that from my test Module and didn't edit it for Sheet. Here's the code to put in your Sheet code module.
Option Explicit

VBA Code:
Sub ResizeNotes()
Dim nt As Shape, shps(), i As Integer
ReDim shps(Me.Shapes.Count)
i = 0
For Each nt In Me.Shapes
    Set shps(i) = nt
    shps(i).Width = 500
    shps(i).Height = 500
    i = i + 1
Next nt
End Sub
 
Upvote 0
No worries, thank you so much for the help. I tried to run this and I got a compile error: invalid use of Me keyword.
 
Upvote 0
No worries, thank you so much for the help. I tried to run this and I got a compile error: invalid use of Me keyword.
You pasted into Sheet code module?
1727566305405.png
 
Upvote 0
Sorry for the slow reply, but I just got back to work on this. I did it wrong the first time but I just ran the code and it worked perfectly. The only problem is some of the images that were cut off are still cut off now but they're just bigger. I can edit them manually by going edit note - format comment - size and then manually adjust the height. I have to uncheck lock aspect ratio first. So maybe the problem is that the aspect ratios are locked. If so is there a macro I can use to automatically unlock all of them first before running this macro?
 
Upvote 0
They're all reasonably similarly sized but no they're not exactly the same. I think unlocking the aspect ratio and then running the macro you provided would be sufficient though.
 
Upvote 0
Let me know if this works. I think we can play around with the size to get you desired results. I've added a Lock Aspect Ration statement.
VBA Code:
Sub ResizeNotes()
Dim nt As Shape, shps(), i As Integer, ff
ReDim shps(Me.Shapes.Count)
i = 0
For Each nt In Me.Shapes
    Set shps(i) = nt
    Set ff = shps(i).Fill
    shps(i).Width = 500
    shps(i).Height = 500
    ff.Parent.LockAspectRatio = True
    i = i + 1
Next nt
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,222,908
Messages
6,168,973
Members
452,228
Latest member
just4jeffrey

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