Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Pasting a Table (Word 97)

    I created a macro button to specifically paste a table.
    Now, I need to error check, verifying that the active contents on the clipboard is in fact a Table, Prior to pasting.

    Something like" If Active Clipboard = Table, then Paste //// Else Msgbx 'The contents of your clipboard is not a table. You can not perform this action at this time.' vbOK


    *****
    History: The tables that we are inserting have a column with ID numbers. When the tables were pasted into a new document, MSWord threw off the formatting by turning on the auto numbering for that column (they thought they knew what we wanted, WRONG). To prevent this, I paste the table, Select the entire table and remove auto numbering by inserting the code line "Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph".
    *****

    <font face="Comic Sans MS">I suspect that it has something to do with recognizing (verifying) the active clipboard's contents type - I base this on the fact that if I DO have a table on my active clipboard and click EDIT, the Paste has changed to Paste Cell.
    </font face=comic>

  2. #2
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    New York, New York, USA
    Posts
    266
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Re: Pasting a Table (Word 97)

    Not sure this will help but maybe by using "DATA OBJECT" in VBA you might be able to solve this. The built in help for Word VBA has an explanation and example of the use of DATA OBJECT.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Pasting a Table (Word 97)

    I don't have any idea how to sniff the format on the clipboard. Sounds like a Windows API question.

    Could you work around the issue by disabling the AutoFormat as You Type setting that messes up your table? (You could store the user's original setting and restore it after you paste, to be more polite.)

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Pasting a Table (Word 97)

    You can use the GetFormat method of a DataObject to find out whether a particular format is present / supported. As in the example in <post#=200297>post 200297</post#>.

    I can't find a decent list of the valid ID numbers for this method. There is a list of format names at http://msdn.microsoft.com/library/default....oardformats.asp

    None of these seems to distinguish a table from other rich text.

    If I select and copy a table, or some plain text, then the only formats I get are 1 and 13, which I think are are "Text" and "Unicode Text".

    StuartR

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pasting a Table (Word 97)

    hi Musical1,

    the dataobject will not allow you to make this distinction, maybe there's an appropriate api functiun to test whether the clipboard contains a table or not, but i don't know it.
    you could however paste to a temporary document and then examine the contents of the document to see if the clipboard contains a table. this is feasable if the tables are not too big:

    function ClipboardContainsTable() as boolean
    dim TableDocument as document
    'application.screenupdating=true
    set tabledocument=documents.add
    with tabledocument
    .content.paste
    clipboardcontainstable=.tables.count>0
    .close savechanges:=wddonotsavechanges
    end with
    'application.screenupdating=true
    end function

    also try to play with the options.AutoFormatAsYouTypeApplyTables setting to avoid the column to be converted.

    greetings,

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Pasting a Table (Word 97)

    This is probably going to be a lot more reliable than Windows API methods (based on an hour of trying that last night). The Documents.Add method allows you to create the new document as hidden (Visible:=False). This will be easier on your users than seeing a screen flash, once you are confident that the idea works for your application.

    This might be new to Word 2000 and higher. If so, never mind.

  7. #7
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pasting a Table (Word 97)

    hi Jefferson, Musical1,

    As Musical1 mentioned word 97 explicitly in his/her post, i didn't provide the visible switch which is not available in word 97, but as an alternative i included the application.update=false and ...=true which essentially achieves the same. to be complete, i list the corrected function below, together with a small sub to demonstrate the use of the function :

    sub testfunction
    if clipboardcontainstable then
    msgbox "Table in Clipboard!"
    else
    msgbox "No Table!"
    end if
    end sub

    function ClipboardContainsTable() as boolean
    dim TableDocument as document
    dim ScreenUpdate as boolean
    screenupdate=application.screenupdating
    application.screenupdating=false
    set tabledocument=documents.add
    with tabledocument
    .content.paste
    clipboardcontainstable=.tables.count>0
    .close savechanges:=wddonotsavechanges
    end with
    application.screenupdating=screenupdate
    end function

    after carefully rereading Musical1's post, i found another way still to test if the cliboard contains a table, which involves reading the caption of the changed control; this would be much faster as it doesn't involve pasting to a temporary document. i must say i'm not confident of the exact caption of the control, as i'm testing here in dutch, and the caption includes an & which points to the menu's shortcut key. IIRC, it's also p for the english version, so the control's caption will start with the ampersand (&). here's the modified function which can be used in exactly the same way:

    function ClipboardContainsTable() as boolean
    clipboardcontainstable= _
    ucase(commandbars("edit").FindControl(id:=22).Capt ion) _
    ="&PASTE CELL"
    end function

    greetings,

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Pasting a Table (Word 97)

    That's a great observation on the changing Caption. Here's what I found in English (U.S.):

    <table cellpadding=5 border=1><td>Clipboard Contents</td><td>Paste caption</td><td>Plain text selected and copied:</td><td> &Paste</td><td>One cell selected and copied:</td><td> &Paste Cells (yes, plural)</td><td>Multiple cells selected and copied (but not an entire column or end-of-row-marker):</td><td> &Paste Cells</td><td>One column selected and copied:</td><td> &Paste Columns</td><td>One row (including end-of-row marker) selected and copied:</td><td> &Paste Rows</td><td>Entire table selected and copied:</td><td> &Paste Rows</td><td>Entire table and anything before or after it:</td><td> &Paste</td></table>
    Depending on how much control the program has, this might be just the thing. Cool.

Posting Permissions

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