PDA

View Full Version : Solved: Unlocking an embedded object



primaryteach
01-13-2010, 09:08 AM
Hi everyone,

I have this piece of code that inserts an embedded file to a worksheet. This works well. However, I wish to use this on a protected sheet where other users can access the attached file but by default an inserted object is 'locked'. How can I change the code so that the inserted file (vFile) is changed to being 'unlocked' to allow access to it?

Thanks in advance,

Simon

Private Sub CommandButton1_Click()
Dim vFile As Variant
ActiveSheet.Unprotect "pass"
Range("F26").Select
vFile = Application.GetOpenFilename("All Files,*.*", Title:=" Find file to insert")
If LCase(vFile) = "false" Then Exit Sub
ActiveSheet.OLEObjects.Add Filename:=vFile, Link:=False, DisplayAsIcon:=True, IconLabel:=vFile
ActiveSheet.Protect "pass", _
Contents:=True, _
UserInterfaceOnly:=True
ActiveSheet.EnableAutoFilter = True
ActiveSheet.EnableOutlining = True
End Sub

RolfJ
01-13-2010, 10:08 AM
I have tested your code on a password-protected worksheet and don't see a problem with accessing the attached file. Could it be that there is something else going on with your workbook?

primaryteach
01-13-2010, 10:54 AM
Rolf,

Thanks for the reply. I've been back to my workbook and it is working now, so I don't know what I was doing earlier when the file couldn't be accessed! Doh!

Regards,

Simon