Unprotect insertpicture in a object protected sheet RRS feed

  • Question

  • hi

    i have design a CV form and used vba formula to make an insert picture button in my sheet, as below:


    Sub InsertPicture()

        Dim oPic        As Picture
        Dim sFilename   As String

        'Prompt user for file
        sFilename = Application.GetOpenFilename( _
                        filefilter:="Pictures (*.jpg;*,bmp;*.gif;*.tiff), *.jpg;*,bmp;*.gif;*.tiff", _
                        Title:="Insert Picture", _

        'If the user cancels, exit the sub
        If sFilename = "False" Then Exit Sub

        'Insert the picture in the active sheet
        Set oPic = ActiveSheet.Pictures.Insert(sFilename)

        'Set the properties
        With oPic
            .ShapeRange.LockAspectRatio = msoTrue
            .Left = Range("J9").Left
            .Top = Range("J9").Top
            .Width = Range("J9:J9").Width
            .Height = Range("J9:J12").Height

        End With

    End Sub

    also i must use protection in my sheet because i have some pictures in it and they must not move, resize or delete at all. but when protection is activate this formula doesn't let the picture insert. please help me, what should i do?

    Thursday, May 3, 2018 6:19 AM

All replies

  • Before you insert the picture, use


    or if you set a password

        ActiveSheet.Unprotect Password:="secret"

    and just above End Sub, insert



        ActiveSheet.Protect Password:="secret"

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, May 3, 2018 8:20 AM
  • Thank you so much dear Hans
    Saturday, May 5, 2018 2:39 PM