none
Clear "large amount of text on the Clipboard" in Word

    Question

  • My apologies if this has been answered elsewhere or is posted in the wrong forum - but I cannot find the answer!

    I have a Word macro that copies a large amount of data from a source file into a document, formats the data, names the document and places it in the correct location on a network drive.  But when the macro ends, I get the message "You placed a large amount of text on the Clipboard. do you want this text to be available to to other applications after you quit Word?". 

    I either want to suppress the message  or clear the clipboard so the message does not appear.   I can do this in Excel, but not Word.

    Many thanks in advance!

     

    Paul

    Wednesday, January 18, 2012 4:13 PM

Answers

  • Hi Paul

    OK, you use Selection.Copy to do the copying. You then close the window (it might actually be better to close the DOCUMENT, not the Window...), paste into the current selection (which one has to assume is a different document - but this code isn't very robust).

    So at this point, focus is in the target document and, assuming the version of Word you're using behaves like the one I'm looking at, after Selection.Paste the cursor is blinking at the end of the document.

    What we're going to do, therefore, is select one character going backwards and copy it. Try this:

    Selection.MoveStart wdCharacter, -1
    Selection.Copy
    Selection.Collapse wdCollapseEnd
    




    Cindy Meister, VSTO/Word MVP
    • Marked as answer by pdking77 Friday, January 20, 2012 4:59 PM
    Friday, January 20, 2012 3:44 PM

All replies

  • Hi Paul

    In Word, we traditionally select a single character and copy that. It replaces the larger amount of data on the Clipboard and shouldn't trigger the message.


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 18, 2012 4:40 PM
  • Cindy,

    Thanks for the quick response! 

    I'm a relative newb to creating/editing macros.  Could you give me an example to get me started?

     

    Thanks!

     

    p

    Wednesday, January 18, 2012 4:52 PM
  • Hi p

    You already have a macro that's doing copying, according to your original message. Could you show us the line of code that's doing the copying, please? (Otherwise we could end up giving you code that won't work in your situation...)


    Cindy Meister, VSTO/Word MVP
    Thursday, January 19, 2012 6:48 AM
  • Cindy,

    It's actually a 'private sub' that runs in the Word macro itself.  The "main" macro just sets the the template, runs this sub, then names the final document and places it in a specific folder on a network drive.  But this is the part that does the heavy lifting:

     

    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
       
    If aAppendix = "O" Then
       Documents.Open FileName:= _
          "\\rmtdrv\home\third\Vfourth\Vfifth\upperdeck\" & aBuild & "\" & aSegment & "\Copy\doc_inventory.txt", _
          ConfirmConversions:=False, _
          ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
          PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
          WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
    End If
       
    'Set the document view to Normal for the document we just opened
    'this will help us performance wise because Word will not paginate
    ActiveWindow.View.Type = wdNormalView
       
    'Select the entire document
    Selection.WholeStory

    'Convert the tab delineated text to a Word table
    Selection.ConvertToTable Separator:=wdSeparateByTabs, AutoFitBehavior:=wdAutoFitFixed
       
    'Apply some formatting to table
    With Selection.Tables(1)
       .Style = "Table Grid"
       .ApplyStyleHeadingRows = True
       .ApplyStyleLastRow = True
       .ApplyStyleFirstColumn = True
       .ApplyStyleLastColumn = True
    End With
       
    'Count how many columns are in are new table
    myColumns = ActiveDocument.Tables(1).Columns.Count

    'This macro only knows how to format column widths for tables with 2, 3, 4, or 7 columns
    If myColumns = 2 Then
       Selection.Tables(1).Columns(2).PreferredWidth = InchesToPoints(2)
       Selection.Tables(1).Columns(1).PreferredWidth = InchesToPoints(5.5)
    ElseIf myColumns = 3 Then
       Selection.Tables(1).Columns(3).PreferredWidth = InchesToPoints(4)
       Selection.Tables(1).Columns(2).PreferredWidth = InchesToPoints(1.5)
       Selection.Tables(1).Columns(1).PreferredWidth = InchesToPoints(2)
    ElseIf myColumns = 4 Then
       Selection.Tables(1).Columns(4).PreferredWidth = InchesToPoints(1.03)
       Selection.Tables(1).Columns(3).PreferredWidth = InchesToPoints(1)
       Selection.Tables(1).Columns(2).PreferredWidth = InchesToPoints(0.85)
       Selection.Tables(1).Columns(1).PreferredWidth = InchesToPoints(7.35)
    ElseIf myColumns = 7 Then
       Selection.Tables(1).Columns(7).PreferredWidth = InchesToPoints(1)
       Selection.Tables(1).Columns(6).PreferredWidth = InchesToPoints(0.84)
       Selection.Tables(1).Columns(5).PreferredWidth = InchesToPoints(1)
       Selection.Tables(1).Columns(4).PreferredWidth = InchesToPoints(0.84)
       Selection.Tables(1).Columns(3).PreferredWidth = InchesToPoints(0.84)
       Selection.Tables(1).Columns(2).PreferredWidth = InchesToPoints(0.84)
       Selection.Tables(1).Columns(1).PreferredWidth = InchesToPoints(4)
    Else
       'If the table is not of 2, 3, 4, or 7 columns then error
        MsgBox "Cannot format the text in this document. Document will not be imported"
        ActiveDocument.Saved = True
        ActiveWindow.Close
        Exit Sub
    End If
       
    'Format the text in the table
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    Selection.Font.name = "Arial"
    Selection.Font.Size = 10
    Selection.Font.Bold = False
    Selection.Cells.VerticalAlignment = wdCellAlignVerticalBottom
      
    'Format the table rows
    Selection.Tables(1).Rows.AllowBreakAcrossPages = False
    Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
       
    'Format the first row of the table that is assumed to be the table header
    ActiveDocument.Tables(1).Rows(1).Select
    Selection.Font.name = "Times New Roman"
    Selection.Font.Bold = True
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Shading.Texture = wdTexture20Percent 'Shade 1st row to 20% Gray
    Selection.Rows.AllowBreakAcrossPages = True
    Selection.Rows.HeadingFormat = True            'Put header row at the top of each page
       
    'Select the entire newly formated document
    Selection.WholeStory
       
    'Copy it to the clipboard
    Selection.Copy
       
    'Tell Word that the document has been saved even though it has not, so word
    'won't try to or ask us to save.
    ActiveDocument.Saved = True
       
    'Close the document
    ActiveWindow.Close
       
    'Paste the new table into our template
    Selection.Paste
       
    'Table, Show Table Gridlines:
    ActiveWindow.View.TableGridlines = True

     

     

    Thanks again!

    Paul

    Thursday, January 19, 2012 8:24 PM
  • Hi Paul

    OK, you use Selection.Copy to do the copying. You then close the window (it might actually be better to close the DOCUMENT, not the Window...), paste into the current selection (which one has to assume is a different document - but this code isn't very robust).

    So at this point, focus is in the target document and, assuming the version of Word you're using behaves like the one I'm looking at, after Selection.Paste the cursor is blinking at the end of the document.

    What we're going to do, therefore, is select one character going backwards and copy it. Try this:

    Selection.MoveStart wdCharacter, -1
    Selection.Copy
    Selection.Collapse wdCollapseEnd
    




    Cindy Meister, VSTO/Word MVP
    • Marked as answer by pdking77 Friday, January 20, 2012 4:59 PM
    Friday, January 20, 2012 3:44 PM
  • Cindy,

    It worked!  I tested it pretty hard - with the three lines in and again ticked out.  Even with a final doc that had 1.5m characters/444 pages. 

    Many thanks!

     

    Paul

    Friday, January 20, 2012 4:59 PM