+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Clipboard-related run-time error

    I'm working on a macro that will generate a word doc, do some formatting, and insert user-selected rows from a spreadsheet.

    My code often produces a clipboard-related run-time error, but I don't see any rhyme or reason in why and when this occurs. One pattern: the more time I leave between running instances of the macro, the less likely it appears that the error will occur.

    The exact error is "Run-time error '4605': This method or property is not available because the Clipboard is empty or not valid." Debugger points to the line
    Code:
    msWord.Selection.PasteExcelTable False, True, False
    I think this might have something to do with a) system resources / clipboard performance, b) error handling / managing multiple instances of word .... but I'm really not sure.

    Full code:

    Code:
    Private Sub cmdSendToWord_Click()
        Dim i
            Dim msWord As Object
            Set msWord = CreateObject("Word.Application")
            msWord.Visible = True
            msWord.Documents.Add
        With msWord
            .Selection.TypeParagraph
            .Selection.InsertDateTime DateTimeFormat:="M/d/yyyy", InsertAsField:=False, _
                DateLanguage:=1033, CalendarType:=0, _
                InsertAsFullWidth:=False
            .Selection.TypeParagraph
            .Selection.TypeParagraph
            .Selection.TypeText Text:="Dear "
            .Selection.FormFields.Add Range:=.Selection.Range, Type:=70
            .Selection.TypeText Text:=":"
            .Selection.TypeParagraph
            .Selection.Font.Size = 1
            .Selection.TypeParagraph
            .Selection.Font.Size = 11
            .ActiveDocument.FormFields("Text1").Result = "RECIPIENT"
            .Selection.FormFields.Add Range:=.Selection.Range, Type:=70
            .ActiveDocument.FormFields("Text2").Result = "INTRODUCTORY TEXT"
        End With
        i = 4
        Do
            If Range("B" & i).Text = "" Then
                Exit Do
            End If
            
            If Range("e" & i).Text = True Then
                Range("B" & i, "D" & i).Copy
    '            msWord.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
                 msWord.Selection.PasteExcelTable False, True, False
    '            msWord.Selection.TypeParagraph
            End If
            i = i + 1
        Loop
        msWord.Selection.TypeParagraph
        msWord.Selection.FormFields.Add Range:=msWord.Selection.Range, Type:=70
        msWord.ActiveDocument.FormFields("Text3").Result = "CONCLUDING TEXT"
        Application.CutCopyMode = False
        ActiveSheet.Shapes("Picture 125").Copy
        msWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
        msWord.ActiveWindow.ActivePane.View.SeekView = 9
        msWord.ActiveWindow.Selection.Paste
        msWord.ActiveWindow.ActivePane.View.SeekView = 0
        msWord.ActiveDocument.FormFields.Shaded = Not msWord.ActiveDocument.FormFields.Shaded
        msWord.ActiveDocument.Protect Type:=2, NoReset:=True
    End Sub

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Clipboard-related run-time error

    This belongs in the Word forum, huh?
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Clipboard-related run-time error

    I didn't think so -- I'm generating things from Excel. But if that makes more sense, A-OK.
    Last edited by prawer; 10-16-2009 at 09:10 PM. Reason: A-OK

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0