Make text paragraph with VBA only (Microsoft Word 2003)

Is there a way to make a paragraph in a Microsoft Word 2003 document readable using VBA only?

0


source to share


3 answers


I think you can do this by selecting the paragraphs that will not be protected .

Below is an example of a macro that selects a piece of text, allows it to be edited, and then locks the rest of the document. You can use IRM or password protection, the macro below uses the latter. You should replace the selection method below with something more elegant



Selection.MoveLeft Unit:=wdCharacter, Count:=11, Extend:=wdExtend 
Selection.Editors.Add wdEditorEveryone
ActiveDocument.protect Password:="password", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False

      

+1


source


You might be able to do this by throwing the protected text into the text form and protecting it. Obviously a little rough.



0


source


The answer above will highlight the yellow edit area selection.

One option is to add this AutoOpen code http://answers.microsoft.com/en-us/office/forum/office_2010-word/remove-highlighting-in-editable-areas-of-protected/bfe22585-c5d3-4c19- 997f-092fc4aaaa7a

Sub AutoOpen()
   ActiveWindow.View.ShadeEditableRanges = False
End Sub

      

In Word 2007 (tested), a more direct way is to create rich text content and set properties. This will easily make the paragraph read-only without doing any highlight events.

Sub LockContent()

Dim objCC As ContentControl
Set objCC = ActiveDocument.ContentControls.Add(Type:=wdContentControlRichText)

With objCC
    .Range.Text = "123123" 'Your text
    .LockContentControl = True
    .LockContents = True
End With

End Sub

      

More ContentControl.LockContentControl content at https://msdn.microsoft.com/en-us/library/office/ff835775.aspx

Hope this helps someone who has the same headache!: D

0


source







All Articles