I have a word doocument that I have the readOnly property set to prevent the user from accidently changing the doc. I have VBA code for filling in text in the document. There is one change to the document that I need to have changed while the user is running the macro and I need it to be invisible to the user. I am able to change the attributes of the file, but it seems like they don't take effect until the document is closed. I even tried to 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?
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.FullName
SetAttr FPath, vbNormal 'this works if you look in explorer it is changed
ActiveDocument.Save
SetAttr FPath, vbReadOnly
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.FullName
SetAttr FPath, vbNormal 'this works if you look in explorer it is changed
ActiveDocument.Save
SetAttr FPath, vbReadOnly