Opening a jpg file

User avatar
HansV
Administrator
Posts: 78556
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening a jpg file

Post by HansV »

1. You can use part of the code for CommandButton1:

Code: Select all

Private Sub CommandButton2_Click()
  Dim shp As Shape
  Dim MyRange As Range

  Set MyRange = Range("C4")

  For Each shp In ActiveSheet.Shapes
    If shp.Top = MyRange.Top And shp.Left = MyRange.Left Then
      shp.Delete
      Exit For
    End If
  Next shp
End Sub
2. You have to unprotect the sheet before inserting the picture and re-protect it afterwards:

Code: Select all

  ActiveSheet.Unprotect
  ' Code to manipulate pictures here
  ...
  ActiveSheet.Protect
If you have specified a password, add it (enclosed in quotes) after both the Unprotect and Protect instructions.
Best wishes,
Hans

Nasser
StarLounger
Posts: 56
Joined: 11 May 2010, 10:26

Re: Opening a jpg file

Post by Nasser »

Hi,

Deleting the picture is working fine, thanks.

About the protection. I tell you what i am doing and then you get the idea.

I give to the student an exercice on a device. After opening the protected sheet, the student answers the questions and also can see the picture of the device if he or she likes and then close the picture once viewed.

When the document is given to the student it is entirely protected from the begining. Opening of the picture should not activate the protection. Everything is protected already by the instructor.

Many thanks,
Nasser.

User avatar
HansV
Administrator
Posts: 78556
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening a jpg file

Post by HansV »

OK, so if the worksheet is already protected, you have to unprotect it in your code before adding or deleting a picture, and protect it again afterwards.
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Opening a jpg file

Post by Don Wells »

HansV wrote:Perhaps something like this:

Code: Select all

  Static HasRun As Boolean
    I'm having some difficulty understanding the Static statement. How is the resulting variable different from a variable declared at the module level?

T.I.A.
Regards
Don

User avatar
HansV
Administrator
Posts: 78556
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening a jpg file

Post by HansV »

A static variable is local to the procedure (sub) or function it is declared in. It is not visible to other procedures and functions, whether in the same module or in another one. This means that you can use a variable of the same name in more than one procedure or function and update the value in each independently of the others.

For example, if you want to keep track of whether each of two procedures has been run, you can use

Static HasRun As Boolean

in both of them instead of having to use two different names.
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Opening a jpg file

Post by Don Wells »

Thank you Hans.
    That point hit me about 30 seconds after I posted the question.
     :blush: I believe the French have a quotation along the lines of "Third step response.", where the indignant departing individual thinks of what they should have said on the third step of the exit stairway.
Regards
Don