Consulting

Results 1 to 2 of 2

Thread: Word Macro to attach file to a form

  1. #1
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    1
    Location

    Word Macro to attach file to a form

    I have a form I have been working with. The form it self need to be protected. I don't know much about VBA programming so there lies my issue.

    I have this button with this code to it.

    Private Sub Bilaga_Click()
    ' Browse & Select File
    With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = True
            .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, "\"))
    What I need it to do is to add the attached file to a textbox or some other means in the protected document.
    I know the above code attache the file to the form but only works when unprotected.

    Any help is appreciated

  2. #2
    There are some things that cannot be achieved when the form is locked. You could unlock the form, perform the action then lock it again.
    Alternatively you could convert your form to use Content Controls which don't require the form be locked.

    If Not ActiveDocument.ProtectionType = wdNoProtection Then
            ActiveDocument.Unprotect Password:=""
        End If
    
    'Do Stuff
    
    ActiveDocument.Protect _
                    Type:=wdAllowOnlyFormFields, _
                    NoReset:=True, _
                    Password:=""
    You
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •