PDA

View Full Version : Make Document as Readonly upon opening



atzdgreat
11-10-2017, 11:10 PM
hello there. I saw a post about making the workbook as readonly upon opening



Private Sub Workbook_Open()
ActiveWorkbook.ChangeFileAccess Mode:=xlReadOnly, WritePassword:=""
MainWindow.Show
End Sub


how about in Word Document?



Private Sub Document_Open()
ActiveDocument.ChangeFileAccess Mode:=xlReadOnly, WritePassword:="" 'This doesn't work.
MainWindow.Show
End Sub

macropod
11-12-2017, 04:21 PM
If you're using Word, you really should pay attention to the Word VBA object model. For starters, xlReadOnly is an Excel constant, not a Word one. That should give you a clue. Furthermore, in Word, it would be pretty obvious if you used the VBE Intellisense or the VBA Help that .ChangeFileAccess is not a Word method.

Moreover, if you want a document to open as read-only, why not save it that way and avoid the complications of needing to save the document with a macro a user might disable?

That said, if you're wedded to the current approach, you could use:
ActiveDocument.ReadOnly = True

atzdgreat
11-13-2017, 07:33 PM
thank you for your reply macropod :)