Moving Comment box with VBA

hoffmand

New Member
Joined
Mar 17, 2009
Messages
1
Hi,

I'm just learning how to use VBA and am stuck trying to change the default position of a comment box I'm creating. What code do I need to insert to move the location of the box from it's default lower right position? I'd like it to be centered and below its cell.

Here's the code I've pasted together from various posts on this site. It's works great except for the position.

Sub CommentPic()

Dim sFile As String

sFile = (ActiveCell.Value)

With ActiveCell.AddComment
.Text Text:=""
.Shape.Fill.UserPicture sFile
.Shape.ScaleWidth 6, msoFalse, msoScaleFromTopLeft
.Shape.ScaleHeight 7.5, msoFalse, msoScaleFromTopLeft
End With

End Sub

Thanks,
Dave
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi, Dave,

this code should get you going:

Code:
Sub PlaceComment()

  Dim rngCell As Range
  Dim lngLeft As Long
  Dim lngTop As Long
  Const cstrPICTURE As String = "C:\WINDOWS\granit.bmp"
  
  Set rngCell = Range("G4")
  If rngCell.Comment Is Nothing Then
    With rngCell
      .AddComment
      lngTop = .Top
      lngLeft = .Offset(0, 1).Left
      With .Comment
        .Visible = True
        .Text Text:=""
        .Shape.Top = lngTop
        .Shape.Left = lngLeft
        .Shape.Fill.UserPicture cstrPICTURE
      End With
    End With
  End If
  
  Set rngCell = Nothing

End Sub
Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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