• Pasting a Table (Word 97)

    Author
    Topic
    #379728

    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”.
    *****

    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.

    Viewing 2 reply threads
    Author
    Replies
    • #634490

      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.

    • #634564

      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.)

      • #634569

        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.

        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[/url]

        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

    • #634606

      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,

      • #634756

        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.

        • #634865

          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).Caption) _
          =”&PASTE CELL”
          end function

          greetings,

          • #634985

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

            Clipboard Contents Paste caption
            Plain text selected and copied: &Paste
            One cell selected and copied: &Paste Cells (yes, plural)
            Multiple cells selected and copied (but not an entire column or end-of-row-marker): &Paste Cells
            One column selected and copied: &Paste Columns
            One row (including end-of-row marker) selected and copied: &Paste Rows
            Entire table selected and copied: &Paste Rows
            Entire table and anything before or after it: &Paste

            Depending on how much control the program has, this might be just the thing. Cool.

    Viewing 2 reply threads
    Reply To: Pasting a Table (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: