×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

(OP)
Hello All;

I am working on attaching documents to a word form using VB to unlock the form, attach a document, and then relock the form. The issue is when I attempt to open the document from the form.

Current Code to attached the document (working):

CODE

Sub Add_table_file_attach()

'Unlock the document

If ActiveDocument.ProtectionType <> wdNoProtection Then
    
        ActiveDocument.Unprotect Password:="test"
        
    End If
    
    
' Add 1 cell in a table

    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
        1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
        
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With

' Attach document in table

    Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:= _
        "", LinkToFile:=False, _
        DisplayAsIcon:=False
        
        
If ActiveDocument.ProtectionType <> wdNoProtection Then
    
        myDoc.Password = "test"
        
    End If

'Re-Locks the Document

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, Password:="test"


End Sub 



So the above code works to allow a file to be added from a button command when called. What I think I need to do for the open file function is to name the attached file as a public variable so that the open function can then open the specific file. Unfortunately, I do not know what code to use to assign the file name as a variable.

Any ideas?

Thanks,

Mike

RE: MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

(OP)
Bump

RE: MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

(OP)
Update:

So I spent a lot of time researching different ways to protect / unprotect a section where I can add the files and allow them to be opened.

CODE

ActiveDocument.Sections(2).ProtectedForForms = False 

The question is, In the section, can you limit the type of edits that can be made?

Thanks,

Mike

RE: MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

(OP)
Resolved:

Here is the code:

CODE

Private Sub ref_doc_Click()

'Focuses on the Reference Document unlocked section 6

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=6, Name:=""



'add reference docunment into reference document section

    Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:= _
        "", LinkToFile:=False, _
        DisplayAsIcon:=False

Call TOC

End Sub 

RE: MS Word VB Form Document Attachment - Unlock / Open file / Re-lock

(OP)
All:

So I had to add a section to the document and something is now allowing the section to be edited both by adding text, deleting text, or deleting the added file after the ref_doc code is run. Previously, after the file is added, it could not be removed and text on the form outside the fields could not be added, changed, or deleted. Any help would be appreciated.

What should be updated?

Thanks,

Mike

Current Code:

CODE

Private Sub ref_doc_Click()

'Focuses on the Reference Document unlocked section 7 - Reference Documents - Attachment (if section number changes, update Count:= # to reflect the change.

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=7, Name:=""



'add reference docunment into reference document section

    Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:= _
        "", LinkToFile:=False, _
        DisplayAsIcon:=False

Call TOC

End Sub 

TOC Code

CODE

Private Sub TOC()

' Macro updates the Table of Contents

Application.ScreenUpdating = False

Call pass_unlock

activedocument.TablesOfContents(1).Update


Call pass_lock

Application.ScreenUpdating = True


End Sub 

Unlock Code:

CODE

Private Sub pass_unlock()

'Unlocks the form.  DO NOT CHANGE THE PASSWORD

If activedocument.ProtectionType <> wdNoProtection Then

    activedocument.Unprotect Password:="logspec"
    
End If


End Sub 

Lock Document code:

CODE

Private Sub pass_lock()

'Locks the form.  DO NOT CHANGE THE PASSWORD

activedocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, Password:="logspec"

End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close