Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Corrupt table in 2013

    Since Word 2003 I have used the following code (a more elaborate version, but this is sufficient to illustrate my problem) to add a label document, and then copy and paste the table as many times as needed.

    Code:
    Sub LabelDuplicate()
        Dim rng As Range
        Application.MailingLabel.CreateNewDocumentByID LabelID:="1359804783"
        Set rng = ActiveDocument.Tables(1).Range
        rng.Copy ' Copy Table 1
        rng.Collapse wdCollapseEnd ' collapse to end
        rng.Paste ' paste table 1 -- code failse here: "A table in this document has become corrupted"
        Set rng = ActiveDocument.Range
        rng.Collapse wdCollapseEnd
        rng.Paste
    End Sub
    In Word 2013, I'm having trouble. As noted in the code above, the code fails when I paste the table with the message: A table in this document has become corrupted."

    I can then use Ctrl-V to paste the table that's in the Clipboard without any problem. If I add

    Code:
    rng.Select
    Selection.Paste
    the Selection object pastes the code successfully. I really want to use the Range object for the purpose of my code. Can anyone think of a reason why the VBA Range object would think that the table is corrupted? Interactively, there's no similar issue, nor is there with the Selection object.

    Thanks.

    Later note: I see that rng.InsertParagraphAfter also raise the corrupted table error... I wonder if this is just a problem with the range object.
    Last edited by richardbarrett; 2015-04-24 at 19:11. Reason: Addition

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I'm not getting the same error in my Word 2013 so there is something else going on in your document. Perhaps your template is indeed corrupted in some way.

    In any case if you paste a table at the end of a table then you don't end up with two tables (but could conceivably get a nested table which you most likely don't want). A more direct way of adding rows that probably avoids your error is as follows

    Sub LabelDuplicate()
    Application.MailingLabel.CreateNewDocumentByID LabelID:="1359804783"
    ActiveDocument.Tables(1).Rows.Add 'repeat as necessary
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Thanks. I need the entire table because I want to fill the cells vertically (one column at a time) and want a new complete table on each page. I pared the code down for posting purposes; the original code added a page break before rng.paste.

    The template I was using is several years old, so I suppose corruption is a possibility. But the bit of code I posted was in a new template which I created today... the only bit of code in it.

    Interesting that you are not experiencing the error. I have a couple other installations of Word 2013, and will try this there. As I said, I don't have difficulty when I use the Selection object; the problem is only with the Range object.

    Thanks again.

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    I tried it again after leaving it for a couple hours. It took about 45 seconds to execute the few lines of code... but it was correct. I ran it again, and the time was 4 seconds. That's about right.

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    That is interesting. Perhaps the 'template' was being downloaded afresh from a MS website hence the slower but successful attempt. I have never gone looking for MS templates on this machine so I hadn't downloaded one with that ID on purpose.

    I don't know how the CreateNewDocumentByID works and the 'attached template' is plain old Normal when I go looking at that.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    There's a folder called PageSize (C:\Program Files\Microsoft Office 15\root\office15\PAGESIZE) which contains files with information about all labels (provided by the various manufacturers) in XML format. Interactively, labels are selected by manufacturer and number (Avery 5164). As far as I know, only recording a macro can reveal the Label ID. I did that for hundreds of labels to createa a function for conversion from label number to label ID. Yes, they are all based on the normal template; the rows, columns, gutter space info is read from the XML, as are page margins.

Posting Permissions

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