View Single Post
 
Old 09-20-2019, 07:15 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Something like this should do. Change "Password" to your document password:

Code:
Option Explicit
Private Sub CommandButton2_Click()
  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
  UnProt "Password"
  Application.Selection.InlineShapes.AddOLEObject _
        FileName:=FiletoInsert, _
        LinkToFile:=False, _
        DisplayAsIcon:=True, _
        IconLabel:=Right(FiletoInsert, Len(FiletoInsert) - InStrRev(FiletoInsert, "\"))
  Prot "Password"
End Sub
Sub Prot(strPW As String)
  'A basic Word macro coded by Greg Maxey
  ActiveDocument.Protect wdAllowOnlyFormFields, True, strPW
End Sub
Sub UnProt(strPW As String)
  'A basic Word macro coded by Greg Maxey
  If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect strPW
  End If
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote