Group: microsoft.public.word.vba.general
From: =?Utf-8?B?SmVhbi1HdXkgTWFyY2ls?=
Date: Tuesday, February 19, 2008 9:53 AM
Subject: RE: Locking Master Document

"Derek Reed" wrote:

> Thank for taking time to respond, but unfortunately it does not address my
> question. What you have described is the mechanism for locking subdouments;
> which I already know what to do.
>
> My question is how to lock the Master document. You can do it by moving the
> cursor to a line in the master document and clicking the lock buttom on the
> toolbar; I cannot however work out how to do the same from VBA.

I do not think that button was intend for that purpose, but it does lock the
master document itself while leaving the subdocuments unlocked, which is a
bit weird, no?

In any case, since this is what you need to do, I looked into it and the
only way I managed to make this work with VBA is as follows. The code works
as a toggle because if the master is locked, it will unlock it, and vice
versa.


Sub ToggleLockMaster()

Dim cmdbarOutline As CommandBar
Dim ctrOutline As CommandBarControl
Dim i As Long

If ActiveDocument.IsMasterDocument Then
Selection.HomeKey wdStory

If Not ActiveDocument.ReadOnly Then
ActiveDocument.Save
End If

Set cmdbarOutline = Application.CommandBars("Outlining")

For i = 1 To cmdbarOutline.Controls.Count
Set ctrOutline = cmdbarOutline.Controls(i)
If ctrOutline.ID = 236 Then ctrOutline.Execute
Next
Else
MsgBox "The currently active document is not a master document.", _
vbExclamation, "Cancelled"
End If

End Sub