?
Solved

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

Posted on 2016-11-03
18
Medium Priority
?
165 Views
Last Modified: 2016-11-27
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.
0
Comment
Question by:joseph narh padi
  • 10
  • 6
17 Comments
 
LVL 50

Expert Comment

by:Martin Liss
ID: 41873279
Can you supply a workbook please?
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41873405
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.
0
 

Author Comment

by:joseph narh padi
ID: 41873477
Thank very much.
Mr. Martin, it's the same workbook you worked on.

Neeraj, I'll give you feedback. Thanks very much
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:joseph narh padi
ID: 41873489
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

0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41873492
Line#6 should be like this.....
Sheet1.Shapes("Image2").Picture.Visible = False

Open in new window

0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41873497
Or you may try something like this....

Sheet1.Image2.Picture = LoadPicture("")

Open in new window

0
 

Author Comment

by:joseph narh padi
ID: 41873508
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
0
 

Author Comment

by:joseph narh padi
ID: 41873517
Okay, Thanks
0
 

Author Comment

by:joseph narh padi
ID: 41873525
I used

Sheet1.Image2.Picture = LoadPicture("")

Open in new window


and it gave an error
Method or data member not found
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41873599
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.
0
 

Author Comment

by:joseph narh padi
ID: 41873615
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?
0
 
LVL 33

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41873618
Can you upload the workbook here?
0
 

Author Comment

by:joseph narh padi
ID: 41873725
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.
0
 
LVL 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41873743
You got an error because the name of your image control was Image1 not Image2, see the properties of the Image Control.
Please try this and it should work for you.
Private Sub Workbook_Open()
On Error Resume Next
'Assuming Image1 is the name of image control on Sheet1
Sheet1.Image1.Picture = LoadPicture("")
'Clearing the cells on Sheet1
Sheet1.Range("A1:D5").ClearContents
Sheet1.Range("A1:D5").ClearComments
Sheets("Sheet1").Label1.Caption = ""
Worksheets("Sheet1").Select ' assume you use Sheet1
Cells.Select
Selection.Clear
End Sub

Open in new window

0
 

Author Comment

by:joseph narh padi
ID: 41873779
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
0
 

Author Comment

by:joseph narh padi
ID: 41874065
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?
0
 

Author Closing Comment

by:joseph narh padi
ID: 41903386
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question