Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I presume that xCell is an instance of the class clsPicCell. If so, then
just use Set xCell = Nothing -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) wrote in message oups.com... I have a class that I made, called clsPicCell. Each clsPicCell object has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture.
After calling that just set the class instance to Nothing. Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely sure about scope etc in this case, so you should test that thoroughly) -- Tim Williams Palo Alto, CA wrote in message oups.com... I have a class that I made, called clsPicCell. Each clsPicCell object has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tried that, but it failed to clear the range object in the Excel sheet
or delete the picture. I am going to post the code below. For reference, cmdClear is a command button that the user would click to clear all clsPicCell objects that are associated with the selected range of cells. cmdPlaceXcells is one that creates the clsPicCells (with associated range and picture object). The code runs, it may even be deleting the object from VBA's point of view. However, it doesn't clear the range contents nor does it delete the picture in the Excel spreadsheet. Here's all the code... please let me know if you see where the issue may be. Any help is greatly appreciated. '================== Private Sub cmdClear_Click() Dim rngeSelected As Range Set rngeSelected = ActiveWindow.RangeSelection Dim Cell As Range Dim xCell As clsCellPic Dim cellAddress As String 'remove all corresponding xCells in collXcells For Each Cell In rngeSelected cellAddress = Cell.Address(ReferenceStyle:=xlR1C1) For Each xCell In collXcells If xCell.Name = cellAddress Then collXcells.Remove Cell.Address(ReferenceStyle:=xlR1C1) Set xCell = Nothing End If Next xCell Next Cell End Sub '<====================== '====================== Private Sub cmdPlaceXcells_Click() Dim rngeSelected As Range Set rngeSelected = ActiveWindow.RangeSelection Dim Cell As Range Dim cellPic As clsCellPic Dim picCopy As Picture Dim picQCAnormal As Picture Set picQCAnormal = _ ThisWorkbook.Worksheets("Variables").Pictures("Pic ture 158") For Each Cell In rngeSelected Set cellPic = New clsCellPic With Cell.Parent 'worksheets(2) picQCAnormal.Copy .Paste Set picCopy = _ .Pictures(.Pictures.Count) 'the one just pasted End With With cellPic Set .ThisCell = Cell Set .ThisPic = picCopy .Name = Cell.Address(ReferenceStyle:=xlR1C1) .FormulaR1C1 = "X" End With 'This causes error if cell already has a xcell object. On Error Resume Next collXcells.Add cellPic, Cell.Address(ReferenceStyle:=xlR1C1) On Error GoTo 0 Next Cell End Sub '<===================================== '==========clsPicCell============= Option Explicit '<clsCellPic Private mCell As Range Private mPic As Picture Private mName As String Public Property Set ThisCell(vData As Range) Set mCell = vData End Property Public Property Set ThisPic(vData As Picture) Set mPic = vData Call ReSync End Property Public Property Let Name(vData As String) mName = vData End Property Public Property Get Name() As String Name = mName End Property Public Property Get Address() As String Address = mCell.Address(ReferenceStyle:=xlR1C1) End Property Public Property Let FormulaR1C1(vData As Variant) mCell.FormulaR1C1 = vData End Property Public Property Get FormulaR1C1() As Variant FormulaR1C1 = mCell.FormulaR1C1 End Property Public Function ReSync() With mCell mPic.Top = .Top mPic.Left = .Left mPic.Width = .Width mPic.Height = .Height End With End Function '<================================= |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Tim, creating the clear method worked... though im not sure why
setting the object to nothing wouldn't delete the picture... -Abe Tim Williams wrote: Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture. After calling that just set the class instance to Nothing. Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely sure about scope etc in this case, so you should test that thoroughly) -- Tim Williams Palo Alto, CA wrote in message oups.com... I have a class that I made, called clsPicCell. Each clsPicCell object has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It is the same general idea as instantiating a word object. Setting the
instance to nothing does not close the application. Unless told to close it does not close. Same idea here. You did not tell the range object to clear. You just removed your pointer to that object. The range and the picture exist on their own. The destructor runs on the object when you set it to nothing. You have to do the housekeeping in the destructor (terminate) before loosing your link to the object. It is sort of analagous to the housekeeping that you have to do in C++ or Java when you destroy objects. In VB we are spoiled because usually VB does the housekeeping for us (except in the case of objects). -- HTH... Jim Thomlinson " wrote: Thanks Tim, creating the clear method worked... though im not sure why setting the object to nothing wouldn't delete the picture... -Abe Tim Williams wrote: Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture. After calling that just set the class instance to Nothing. Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely sure about scope etc in this case, so you should test that thoroughly) -- Tim Williams Palo Alto, CA wrote in message oups.com... I have a class that I made, called clsPicCell. Each clsPicCell object has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That helps Jim. Thanks!
-Abe Jim Thomlinson wrote: It is the same general idea as instantiating a word object. Setting the instance to nothing does not close the application. Unless told to close it does not close. Same idea here. You did not tell the range object to clear. You just removed your pointer to that object. The range and the picture exist on their own. The destructor runs on the object when you set it to nothing. You have to do the housekeeping in the destructor (terminate) before loosing your link to the object. It is sort of analagous to the housekeeping that you have to do in C++ or Java when you destroy objects. In VB we are spoiled because usually VB does the housekeeping for us (except in the case of objects). -- HTH... Jim Thomlinson " wrote: Thanks Tim, creating the clear method worked... though im not sure why setting the object to nothing wouldn't delete the picture... -Abe Tim Williams wrote: Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture. After calling that just set the class instance to Nothing. Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely sure about scope etc in this case, so you should test that thoroughly) -- Tim Williams Palo Alto, CA wrote in message oups.com... I have a class that I made, called clsPicCell. Each clsPicCell object has a two objects within it, a range object and a picture object (both private objects). I would like help on how to be able to delete a clsPicCell object, call it xCell. The desired result is that if I code something like: xCell.delete it will clear the range object and delete the picture, and get rid of the object all together. How would I do this? I was unable to find any related topics, so point me in the direction of one if you know of it. Thanks, -Abe |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cant delete user defined default chart type | Charts and Charting in Excel | |||
How do I delete a User defined default excel chart | Charts and Charting in Excel | |||
Delete user-defined charts | Charts and Charting in Excel | |||
User-defined type collection in class module | Excel Programming | |||
Create my own Class Object for Ranges, having trouble assigning name property | Excel Programming |