[RESOLVED] Insert text into a table unprotected section of a protected document-VBForums
Results 1 to 2 of 2

Thread: [RESOLVED] Insert text into a table unprotected section of a protected document

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    Resolved [RESOLVED] Insert text into a table unprotected section of a protected document

    Hi. I am using Word 2003 and have a document that has 3 sections. I have the first section protected leaving the other 2 unprotected. In one of the unprotected sections I have a table. I have a macro that uses a loop to populates that table. Code is:

    For i = 1 To UBound(CAPSID)
    If i <> 1 Then '--if not on first cell in table
    ActiveDocument.Tables(2).Rows.Add '--add a row to the table
    End If

    With ActiveDocument.Tables(2).Cell(Row:=i, Column:=1).Range
    .InsertAfter Text:=CAPSID(i) '--CAPSID is an array that stores text values
    End With
    Next i

    However when I run the macro I get the runtime error 6124: "You are not allowed to edit this region because document protection is in effect". The first part of the code works (inserting a row into the table), but it will not insert text into it. Why am I getting this error if the table is in an unprotected section of the document? I am able to type into the table manually, but running the code throws an error. If I turn off all protection it works fine. I know the work around, but I'd rather not turn off and on protection during the macro. The macro creates a fairly large document (100-150 pages) and has calculated fields. If I unlock and re-lock the document, it refreshes the calculated fields and takes a while to do so since there are so many fields in the large document. I don't see why it shouldn't work if the table is not in a protected part of the document. I wrote this program a long time ago and I don't remember it not working before. I think it may have started not working after moving to Word 2003, but am not sure. Any clues?
    Last edited by mattchorno; Jul 30th, 2009 at 02:14 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    [SOLVED]: Insert text into a table unprotected section of a protected document

    Someone from another forum figured this out. Solution posted below for future prosperity.
    ---------------------------
    As far as I can tell it has to do with the table being linked to the
    document collection of tables, because the document is protected in part,
    the collection is also locked.

    So, you can use the Selection object instead, which does not refer directly
    to the table,.
    Try this:

    With ActiveDocument.Tables(2).Cell(Row:=i, Column:=1).Range
    .Select
    Selection.Collapse wdCollapseStart
    Selection.TypeText CAPSID(i) '--CAPSID is an array that stores
    Text values
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.