Hi,
I am using word automation in Word 2007.
I have a normal .docx file which I want to password protect and latter on show the same to user.
When I open the generated .docx with password, word asks if you want to see the read only or not. There is a button to open as read only. The whole purpose of password protecting the file is lost.
Can someone tell me if the below code is right to generate the password protected file. Not sure if I have to do some setting while saving the file or opening the file to show it to user.
Dim value As Object = System.Reflection.Missing.Value
Dim app As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
Dim doc As Document
Dim missing As Object = System.Reflection.Missing.Value
Dim readOnly1 As Object = False
Dim visible As Object = True
Dim _Password As Object = "abc"
Dim fileToOpen As Object = text
doc = app.Documents.Open(fileToOpen, missing, readOnly1, missing, missing, missing, missing, missing, missing, missing, missing, visible, visible, missing, missing, missing)
doc.Activate()
doc.SaveAs(fileToOpen, missing, readOnly1, missing, missing, _Password, False, missing, missing, missing, missing, visible, visible, missing, missing, missing)
doc.Close(False, False, False)