Consulting

Results 1 to 3 of 3

Thread: Make Document as Readonly upon opening

  1. #1

    Make Document as Readonly upon opening

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    thank you for your reply macropod

Tags for this Thread

Posting Permissions

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