Link to home
Start Free TrialLog in
Avatar of joseph narh padi
joseph narh padi

asked on

HOW D I CLEAR PICTURES IN IMAGE CONTROL AND COMMENTS IN CELLS WHEN WORKBOOK IS OPENED

I have an Image control in my my excel worksheet.
I load pictures into the image ActiveX in the worksheet and add comments to a array of cells A4:D5.
Whenever the workbook is closed and opened the last picture loaded in the image control and the previous riddles (comments) appear, but i don't want it to be so.

When the worksheet is opened the riddles must appear only after the start button is pressed (The previous comments must be cleared when the worksheet is opened)

and

the pictures must load only after the user enters the answer and clicks the submit button.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Can you supply a workbook please?
You may try something like this.....

Private Sub Workbook_Open()
On Error Resume Next
'Assuming Image1 is the name of image control on Sheet1
Sheet1.Shapes("Image1").Visible = False
'Clearing the cells on Sheet1
Sheet1.Range("A4:D5").ClearContents
End Sub

Open in new window

Also in the coding behind the Start button when you want the image to be appeared, you may turn the Visible property to True again.
Avatar of joseph narh padi
joseph narh padi

ASKER

Thank very much.
Mr. Martin, it's the same workbook you worked on.

Neeraj, I'll give you feedback. Thanks very much
Hello Neeraj,
I put this in "This Workbook"
The label is cleared of it's content,
the cells are cleared of their content,
but the image in the image frame is not cleared
and the comments in the cell are not cleared.

Private Sub Workbook_Open()
Dim Image2 As Image

On Error Resume Next
'Assuming Image1 is the name of image control on Sheet1
Sheet1.Shapes("Image2").Picture = ""
'Clearing the cells on Sheet1
Sheet1.Range("A1:D5").ClearContents
Sheet1.Range("A1:D5").ClearComment
Sheets("Sheet1").Label1.Caption = ""
End Sub

Open in new window

Line#6 should be like this.....
Sheet1.Shapes("Image2").Picture.Visible = False

Open in new window

Or you may try something like this....

Sheet1.Image2.Picture = LoadPicture("")

Open in new window

I have modified it to

Private Sub Workbook_Open()
Dim Image2 As Image

On Error Resume Next
'Assuming Image1 is the name of image control on Sheet1
Sheet1.Shapes("Image2").Picture.Clear
'Clearing the cells on Sheet1
Sheet1.Range("A1:D5").ClearContents
Sheet1.Range("A1:D5").ClearComment
Sheets("Sheet1").Label1.Caption = ""
Worksheets("Sheet1").Select ' assume you use Sheet1
Cells.Select
Selection.Clear
End Sub

Open in new window


the comments have been cleared but the picutre in the image is not cleared
Okay, Thanks
I used

Sheet1.Image2.Picture = LoadPicture("")

Open in new window


and it gave an error
Method or data member not found
In the line above, Sheet1 is the code name of the sheet not the sheet name and Image2 is the name of the image control.
Make sure both are found and correct.
Thanks very much.

I'm not sure of how they should be found but the work is in sheet1 and the name of the Image control is Image2.
I declared the Image control.
What else should I do?
Can you upload the workbook here?
Thanks.
I'm currently at work but I posted one in this forum title How to use mouse move event.
Please if you don't mind, you may download it from there.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay. Thanks. But I used image2 for the load picture. And it's reference in the sheet1 method reads
Sub Image2 ()
What constitutes the name then?
Okay I'll check from the property window.

I'll give you feedback as soon as I get home. Thanks  once again
Thanks very much.
I checked from the property window and it is Image1.
I have also realised that i referenced it Image1 in the loadpicture method.
Why then is it referenced Image2 in the worksheet?
If I use design mode and select the image control, it shows in the formula bar on the left "Image2" and on the right "EMBED ("Forms.Image1", "")"
That's why I thought the name was Image2.
Thanks very much. it works perfectly well

I have another post heading

CONDITIONAL FORMATING OF CELLS USING EXCEL VBA CODES

in this forum based on the same workbook. would you mind looking at it?
Thanks very much for your cooperation. I appreciate you for the assistance and the promptness with which you attended to my question. God bless you