Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Moving to next field with F11 in protected document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 12 Apr 2007 02:51 GMT
I have a VBA macro that selects the word to the left of the cursor and
inserts a file of that name into the document. The macro counts the
fields in the document before and after the file is inserted, and if
the number increases (meaning there are fields in the file that was
inserted), it goes to the first field and ends. The user types what he
wants there and advances to the next field using F11. Now we want to
use this macro in a document where part of the document is protected,
and we find not only that the macro will not advance the cursor to the
first field but also that F11 will not move it to the next field, even
though it is in the unprotected part of the document.

I could turn off the protection at the start of the macro, but I don't
have a way to turn it back on, since the macro ends before the user
types into the various fields. Is there any way around this? As a last
resort, I would even settle for turning the protection back on after
some delay to allow the user time to enter the text in the various
fields.

Thanks in advance for any help.

David
Fred - 12 Apr 2007 09:17 GMT
Use the TAB key in protected formfield documents.  F11 only works on
formfields when not protected.
Janine
www.docsliveonline.com

>I have a VBA macro that selects the word to the left of the cursor and
> inserts a file of that name into the document. The macro counts the
[quoted text clipped - 17 lines]
>
> David
David - 12 Apr 2007 17:05 GMT
Thanks for the reply, but the tab key just inserts a tab. F11 does
nothing at all. But if I unprotect the document, then both F11 and the
macro work to move to the next field. This is Word 2003, if that makes
any difference.

> Use the TAB key in protected formfield documents.  F11 only works on
> formfields when not protected.
[quoted text clipped - 23 lines]
>
> - Show quoted text -
Jean-Guy Marcil - 12 Apr 2007 17:36 GMT
David was telling us:
David nous racontait que :

> I have a VBA macro that selects the word to the left of the cursor and
> inserts a file of that name into the document. The macro counts the
[quoted text clipped - 15 lines]
>
> Thanks in advance for any help.

What types of fields do you fnd in the protected parts?

Signature

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

David - 12 Apr 2007 22:13 GMT
> David was telling us:
> David nous racontait que :
[quoted text clipped - 30 lines]
>
> - Show quoted text -

In the protected part, I don't see any fields, but there are a lot of
bookmarks. The users don't have to enter anything there, as it has
already been completed before we get the document. In the unprotected
part, there are about 6,000 files that a user can insert using the
macro. In the ones I looked at that have fields, they are all quote
fields.

This is the line that no longer advances the cursor to the first
field, if that is any help. But I would be satisfied if just F11 would
advance to the next field.

If bk2 > bk1 Then ActiveDocument.Bookmarks("\prevsel1").Select:
Selection.NextField.Select: Selection.MoveRight unit:=wdCharacter,
Count:=1: Exit Sub

Thanks again for any assistance.

David
Jean-Guy Marcil - 12 Apr 2007 23:38 GMT
David was telling us:
David nous racontait que :

>> David was telling us:
>> David nous racontait que :
[quoted text clipped - 46 lines]
> Selection.NextField.Select: Selection.MoveRight unit:=wdCharacter,
> Count:=1: Exit Sub

I am a bit confused because in your original post you seemed to imply that
the inserted file may have some field the users would need to fill in, so
you could not protect the document after inserting the said file. Now you
are saying that the inserted files does not contain any fields..
I guess I am not clear on the over all picture...

Anyway,

   Selection.NextField.Select: Selection.MoveRight unit:=wdCharacter,
Count:=1

will not work if you have a protected section in the document.

But the following will:

   ActiveDocument.Unprotect

   Selection.NextField.Select: Selection.MoveRight unit:=wdCharacter,
Count:=1

   ActiveDocument.Protect wdAllowOnlyFormFields, True

Signature

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

David - 13 Apr 2007 00:49 GMT
> David was telling us:
> David nous racontait que :
[quoted text clipped - 79 lines]
> jmarcilREM...@CAPSsympatico.caTHISTOO
> Word MVP site:http://www.word.mvps.org

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.

Again thanks for your help.
Jean-Guy Marcil - 13 Apr 2007 03:30 GMT
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
[quoted text clipped - 35 lines]
> 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.

Signature

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

David - 13 Apr 2007 04:49 GMT
> David was telling us:
> David nous racontait que :
[quoted text clipped - 123 lines]
> jmarcilREM...@CAPSsympatico.caTHISTOO
> Word MVP site:http://www.word.mvps.org

Merci beaucoup, mon ami! I will try to make it work tomorrow.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.