Exit Macro Does Not Return Insertion Point to Correct Position

ID: Q120670

The information in this article applies to:

SYMPTOMS

If you use an Exit macro in a protected form document to position the insertion point into an unprotected section of the document, Word for Windows positions the insertion point in the next FORM field in your document. This happens regardless of whether your Exit macro reprotects the document.

The following macro demonstrates this problem:

 Sub MAIN
  ToolsUnprotectDocument
  LineDown 3
  Insert "Testing"
  ToolsProtectSection .Section=1, .Protect = 1
 End Sub

Notice that Word positions the insertion point in the next FORM field instead of leaving it after the word "Testing". In addition, you can no longer insert paragraph marks or tabs in your document, and the BACKSPACE key does not work. You must close and then reopen your document to regain full Word functionality.

CAUSE

If your Exit macro re-protects the form document, Word moves to the next FORM field by design. In a protected document, you can position the insertion point only in FORM fields.

If, on the other hand, your Exit macro leaves the form document unprotected, Word's behavior is unexpected.

STATUS

Microsoft has confirmed this to be a problem in the versions of Word listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

Create an Exit macro that unprotects your document and then calls another macro to move the insertion point in your document. The following two sample macros demonstrate this workaround (In these examples, the first section needs to be a protected section):

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Exit Macro (Name: MyMacro1)

 Sub Main
  ToolsUnprotectDocument
  x=Now()
  OnTime x, "MyMacro2"  ' MyMacro2 is the name of the 2nd macro.
 End Sub

Secondary Macro (Name: MyMacro2)

Note: The name of this macro must be the same as the name you use in the OnTime statement in the first macro.

 Sub Main
  EditGoto "s1" ' (Insert the commands here that move the insertion point.)
  Insert "Testing"
 End Sub

The following sample Exit macro reprotects your document after the secondary macro runs:

 Sub Main
    ToolsUnprotectDocument
    x=Now()
    OnTime x, "MyMacro2"
    s=1 'or the number of the section you are protecting
    ToolsProtectDocument .Type=2
    ToolsProtectSection .Section=s, .Protect=1
 End Sub

KBCategory: kbusage kbmacro buglist6.0 buglist6.0a buglist6.0c KBSubcategory: Additional query words: winword 6.0 6.0a 6.0c word6 7.0 word95 word7
Version           : 6.0 6.0a 6.0c 7.0
Platform          : WINDOWS

Last Reviewed: February 5, 1998