View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default A class with two objects?

Abe,
If you write a .Delete method in your class.
e.g.
Public Enum DeleteObj
delPic
delCell
delBoth
End Enum

Public Function Delete (DeleteWhat As DeleteObj)
Select Case DeleteWhat
case delPic
mPic.Delete
case delCell
mCell.Delete xlShiftToLeft
case delBoth
mPic.Delete
mCell.Delete xlShiftToLeft
end select
End Function

And then call it from the WS code
cellpic.Delete delPic
'Release the reference
Set cellpic=nothing

It all depends what you want to achieve.

NickHK

wrote in message
oups.com...
That is AWESOME! It will make the coding for my program a lot easier
(and more understandable). Thanks Nick, I am going to go for making the
class (as oppossed to my earlier posted decision). One question, would
.delete work on a cCellPic object, or do I need to define a function in
the class to do that?

-Abe


NickHK wrote:
Abe,
If you are planning on having many of these cell/pic relationships to
together, it would be pretty easy to create a class for this and a
collection of each on a WS to facilitate resyncing (??) or whatever.

e.g.

<cCellPic
Private mCell As Range
Private mPic As Shape

Public Property Set ThisCell(vData As Range)
Set mCell = vData
End Property

Public Property Set ThisPic(vData As Shape)
Set mPic = vData
End Property

Public Property Let CellWidth(vData As Single)
mCell.ColumnWidth = vData
Call ReSync
End Property

Public Function ReSync()
With mCell
mPic.Top = .Top
mPic.Left = .Left
'Need to calculate the scaling correctly
mPic.ScaleWidth .ColumnWidth / mPic.Width, msoTrue,

msoScaleFromTopLeft
mPic.ScaleHeight .RowHeight / mPic.Height, msoFalse,

msoScaleFromTopLeft
End With
End Function
</cCellPic

<WS code
Dim CellPic As cCellPic

Private Sub CommandButton1_Click()
Set CellPic = New Class1

With CellPic
Set .ThisCell = Range("A1")
Set .ThisPic = ActiveSheet.Shapes("Picture 2")
.CellWidth = ActiveSheet.Range("D1").Value
End With

End Sub

NickHK


wrote in message
ups.com...
Yeah, I knew the cell cannot contain a picture, but each picture would
be associated with a cell via position. I now agree with you and have
decided against constructing an object class... Im going about it a
different way. It would have been slick to be able to modify both the
picture and cell from one object though.

Thanks for the response,

-Abe

Leith Ross wrote:
Hello Abraham,

Technically a cell cannot contain a picture. Excel has a separate
drawing layer for pictures and shapes that are placed relative to a
cell's position. You can control the placement of a shape object or
picture on the worksheet using VBA code. There is really no need to
construct your own object class, which would be far more complex to

do.


Sincerely,
Leith Ross


--
Leith Ross

------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread:

http://www.excelforum.com/showthread...hreadid=556275