View Single Post
 
Old 09-05-2019, 05:13 AM
wolfgrrl wolfgrrl is offline Windows 10 Office 2010
Novice
 
Join Date: May 2019
Posts: 15
wolfgrrl is on a distinguished road
Default Button with VBA to attach a file in a protected document

I've got a form running perfectly with the exception of my "attach" button. I've got this macro attached to my button:

Code:
Private Sub CommandButton2_Click()
' Browse & Select File
With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Title = "Select the File that you want to insert"
        If .Show = True Then
            FiletoInsert = .SelectedItems(1)
        Else
            Exit Sub
        End If
    End With
    
    ' Embed File Inline
    Application.Selection.InlineShapes.AddOLEObject _
        FileName:=FiletoInsert, _
        LinkToFile:=False, _
        DisplayAsIcon:=True, _
        IconLabel:=Right(FiletoInsert, Len(FiletoInsert) - InStrRev(FiletoInsert, "\"))
End Sub
When the document is unprotected. the button works and files attach as expected. However, when I turn protection on in the document, attach fails.

I've got my protection set up as shown in the attachment.

How can I get the attach macro to play nice with the protection?

Thank you!
Attached Images
File Type: png Annotation 2019-09-05 081126.png (11.7 KB, 17 views)
Reply With Quote