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):
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
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