Shape on Cell's Characters Range

D

David McCulloch

Is there a way to associate a shape object with an Excel cell's characters
range?



For example, how could I draw a rectangle around line-2 and line-3 of a cell
that contains 5-lines of text, some of which are split with a line break and
others which are wrapped due to length?



Essentially, I would like to be able to find a way to accomplish the
following logic. Unfortunately, Excel does not allow .Left, .Top, .Width
and/or .Height of a characters range.



======================================================================

Dim h, l, t, w As Long ' Height, Left, Top, Width

Dim strShapeName As String ' Shape Name



' Define Range Selection

With Cells(2, 1).Characters(Start:=8, Length:=13)

l = .Left

t = .Top

w = .Width

h = .Height

End With



strShapeName = "MyRectangle"



' Create Rectangle Shape over Cell's special Text

With ActiveSheet.Shapes.AddShape(msoShapeRectangle, l, t, w, h)

.Name = strShapeName

.Fill.Visible = False

.Line.DashStyle = msoLineLongDash

.Line.ForeColor.RGB = RGB(255, 0, 0)

.Line.Weight = 1.25

End With

======================================================================



Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top