Re: Moving to next field with F11 in protected document



David was telling us:
David nous racontait que :


Sorry I wasn't clear, but you have helped me get started. It's a
little hard to explain. We receive Word documents with information
already completed on the first page and the cursor at the top of the
second page. The information on the first page is what is protected.
On the second page, the users are to write a narrative. We have other
Word files containing most of what needs to be written in the
narrative in the unprotected area beginning on the second page. The
macro is invoked with a keyboard hotkey and looks at the characters to
the left of the cursor until a space is found and then selects that
text. The macro expands six digits that make a valid date into a
spelled out date, and if the selection isn't a valid date it looks for
a file with the name of the selection and inserts one space and then
the file, like an autotext entry would so. Some of these inserted
files contain places where the user has to enter some things, such as
a date or the information from yet another file. An example might be
File1 containing: "The petition dated {Quote} was postmarked on
{Quote}. Precedent case no. {Quote} establishes that where the date of
the document and the postmark differ, the postmark date is the
controlling date." File2 would contain a citation for the precedent
case. When we have used this with our unprotected documents, the user
could type file1 and the hotkey, and the text from file 1 would be
inserted with the insertion point after the word "dated." The user
could enter the six digits for the date and the hotkey to invoke the
macro again to expand the date. Then the user would hit F11 and the
insertion point would move to the location following "postmarked on"
where users would use the macro again to expand that date. Then the
user would hit F11 again to move to the location after "case no."
where he or she would enter File2 and the hotkey to insert the
citation.

Your suggestion solves the problem of putting the insertion point at
the place where the user has to make the first entry, but if the
protection is turned back on after the file is inserted, then F11
won't advance to the next location. If there is no method to advance
to the next field with protection on, then is there a way to delay
turning the protection back on for some period of time, like 1 minute?
This would give the user time to enter the values, but minimize the
chance that he or she would inadvertently change anything on the first
page.



Don't use a delay, too many unforeseen things could happen and screw up both
the document content and the macro execution.

I happen to have some code already written for just this case:

'_______________________________________
Const strFormPass As String = ""

'_______________________________________
Sub NextField()

Dim rgeField As Range
Dim lngStart As Long
Dim lngEnd As Long

ActiveDocument.Unprotect strFormPass

lngStart = Selection.Range.Start
Selection.NextField
'If equals, were at the last field and selection has not changed
'Go to first field in doc.
If Selection.Range.Start = lngStart Then
ActiveDocument.Fields(1).Select
End If
Set rgeField = Selection.Fields(1).Result

ActiveDocument.Protect wdAllowOnlyFormFields, True, strFormPass, , True

rgeField.Select
'If not, the field result is selected, not the whole field and the user will
'type and keep the field, which we do not want as it makes later editing
complicated
'as selecting words or paragraphs in the field is difficult
'The same applies for PrevField
If Not Selection.Sections(1).ProtectedForForms Then
Selection.MoveRight wdCharacter, 1, wdExtend
End If

End Sub
'_______________________________________

'_______________________________________
Sub PrevField()

Dim rgeField As Range
Dim lngStart As Long
Dim lngEnd As Long

ActiveDocument.Unprotect strFormPass

lngStart = Selection.Range.Start
Selection.PreviousField
'If equals, were at the first field and selection has not changed
'Go to last field in doc.
If Selection.Range.Start = lngStart Then
ActiveDocument.Fields(ActiveDocument.Fields.Count).Select
End If
Set rgeField = Selection.Fields(1).Result

ActiveDocument.Protect wdAllowOnlyFormFields, True, strFormPass, , True

rgeField.Select
If Not Selection.Sections(1).ProtectedForForms Then
Selection.MoveRight wdCharacter, 1, wdExtend
End If

End Sub
'_______________________________________

Make sure you do not change the Sub names otherwise you will have to assign
the macros the F11 key and to the SHIFT-F11. With the built-in command
names, the F11 key (or SHIFT-F11) grabs that code automatically.

Also, I have code to select the actual field result and to circle through
the document (from last to first or from first to last when using the
previous field code). You may want to remove-modify that part as you need.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@xxxxxxxxxxxxxxxxxxxxxxx
Word MVP site: http://www.word.mvps.org


.



Relevant Pages

  • Re: Moving to next field with F11 in protected document
    ... macro is invoked with a keyboard hotkey and looks at the characters to ... a file with the name of the selection and inserts one space and then ... Dim rgeField As Range ... Dim lngStart As Long ...
    (microsoft.public.word.vba.beginners)
  • RE: Macro to insert multiple images at specific cells and resize all i
    ... 'Now paste to userselected cell ... enabled selection of multiple files/images but all of the images or then ... inserted into the one cell that is selected as the insertion point. ... Dim ImgFileFormat As String ...
    (microsoft.public.excel.programming)
  • Re: How to replace a string of characters with the count of the ch
    ... Dim AlphabetCountString As String ... I prefer to work with Range objects instead of the Selection whenever ... .MatchWildcards = False ...
    (microsoft.public.word.vba.general)
  • Ws Selection Change Event Code, Copy a Cell problem
    ... The sub below is doing what I want, re: selection. ... Dim RngType As String ... If ChgRow> PaEndRow Then ... Cells(ChgRow, SVrSubscrCol + COfs).Select ...
    (microsoft.public.excel.programming)
  • RE: Emailing With Attachments
    ... Presenting the file list in a combo box for selection ... Dim fso As New FileSystemObject ... 'Try to extract JobNum in the File name ... 'Set objOutlookRecip = .Recipients.Add ...
    (microsoft.public.access.modulesdaovba)