I have a word doocument that I have the readOnly property set to prevent the user from accidently changing the doc. The document has an onOpen macro for creating a form. The user will input his name as a reviewer and this will be placed in a bookmark in the form. This needs to be saved in the original so that the user will now be the default reviewer. I have tried several methods. Change the attributes of the document by SetAttr.Path.vbNormal, which works but when I try to save the document I get a permission error. It seems like the SetAttr isn't recognized by Word until it closes. I even tried to SetAttr, SaveAs with a temporary name and delete the original, but I still get a permission error. Here is the code that I am using so far. If the ReadOnly property is not set, the program runs, and the property is set to ReadOnly after the progrgam finishes. If the ReadOnly property is set the program crashes at the Save function and the ReadOnly property has been removed. Any Suggestions?
The above code gives me a permission error with the .Save command
Dim oRng As Word.Range
Dim BodyText As String
Dim FPath As String
Set oRng = ActiveDocument.Bookmarks("bk1").Range
oRng.Text = ActiveDocument.Bookmarks("bk1").Range.Text
UserName = InputBox("Enter your Name", "Name", oRng)
oRng.Text = UserName
ActiveDocument.Bookmarks.Add "bk1", oRng
FPath = ActiveDocument.FullNameSetAttr FPath, vbNormal
SetAttr FPath, vbReadOnly
I also tried:
I get a permission error with this as well.
strName = .FullName
.SaveAs FileName:=strName & "1"
Kill strName & "1"
I also tried to use a template but can't save the one change to the template via code.
Any suggestions on the best way to do this?