+ Reply to Thread
Results 1 to 5 of 5

Thread: run-time error 4605 when using a macros in excel 2010 (windows 7)

  1. #1
    Registered User
    Join Date
    01-25-2010
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010 and Excel 2007 (Windows 7 and XP mode)
    Posts
    9

    run-time error 4605 when using a macros in excel 2010 (windows 7)

    The following macros (which was created with the help of this forum-thanks) is used to transfer data from excel to several tables within a word document:

    Sub Appendix_table_fill()
    
      Dim C As Long
      Dim FileFilter As String
      Dim LastCol As Long
      Dim R As Long
      Dim Rng As Excel.Range
      Dim T As Integer
      Dim WordFile As String
      Dim wdApp As Object
      Dim wdDoc As Object
      Dim wdTbl As Object
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Summary Table")
        Set Rng = Wks.Range("Q3:Q11")
        
        LastCol = Wks.Cells(Rng.Row, Columns.Count).End(xlToLeft).Column
        Set Rng = Rng.Resize(ColumnSize:=LastCol)
        
          FileFilter = "Word Documents(*.docx),*.docx, All Files(*.*),*.*"
          WordFile = Excel.Application.GetOpenFilename(FileFilter)
        
          If WordFile = "False" Then Exit Sub
        
            T = 4
            Set wdApp = CreateObject("Word.Application")
            Set wdDoc = wdApp.Documents.Open(WordFile)
            
            For C = 1 To LastCol
              Set wdTbl = wdDoc.Tables(T)
                For R = 1 To Rng.Rows.Count
                  wdTbl.Columns(2).Select
                  Rng.Columns(C).Copy
                  wdApp.Selection.Paste
                Next R
              T = T + 5
              If T > wdDoc.Tables.Count Then Exit For
            Next C
            
            Excel.Application.CutCopyMode = False
            wdApp.Visible = True
        
        Set wdApp = Nothing
        Set wdDoc = Nothing
        Set wdTbl = Nothing
        
    End Sub
    I recieve a an error message saying:

    "run-time error 4605

    This method or property is not available because the clipboard is empty or not available"

    Stepping into debugger it stops here: "wdApp.Selection.Paste"

    This code works fine in both excel 2007 and 2010 in XP mode, but is much slower. It seems to only fail in windows 7? It also seems to fail at different points, cutting and pasting into some of the tables then failing.

    Please could you help me determine what is wrong.

    Much appreciated,

    rpt21

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: run-time error 4605 when using a macros in excel 2010 (windows 7)

    Hi rpt21,

    I first believe the error message. Lets go with the clipboard is empty. That would mean that what you thought you copied wasn't there. Looking at the code it refers to a Table(T) and I assume T is a number. If you were refering to table 5 or Table(5) and there was no table 5 in the workbook or document you could easily get this message.

    When it stops next time and you go into the debugger, hover you mouse over the T in Table(T) to see what value it is. Then go to where it is supposed to be pulling the copy from and see if there is really one of those there.
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  3. #3
    Registered User
    Join Date
    01-25-2010
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010 and Excel 2007 (Windows 7 and XP mode)
    Posts
    9

    Re: run-time error 4605 when using a macros in excel 2010 (windows 7)

    Hello MarvinP,

    There is definitely a table where is should paste, the document is made up identical pages and each page has five tables in it. The data is pasted into every 5th table since the other tables contain other content.

    The macros fails at different points, so it is not one table that is problematic.

    This code has worked for a while, it is only since I have upgraded to Windows 7. As I mentioned, it works on my virtual XP but it is annoying to use this each time I need to run this macros.

    regards,

    Ross

  4. #4
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: run-time error 4605 when using a macros in excel 2010 (windows 7)

    Hi rpt21,

    Because it fails at different times and places, I'm thinking some well placed Application.DoEvents might solve the problem.

    Search for VBA DoEvents or look at
    http://en.allexperts.com/q/Visual-Ba...s-Function.htm
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  5. #5
    Registered User
    Join Date
    05-04-2012
    Location
    Zurich
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: run-time error 4605 when using a macros in excel 2010 (windows 7)

    It's been a while, so you may have solved this already, but in case anyone else has a similar problem:

    I started getting this error when I upgraded from MS Office 2003 to 2010, but the macro still worked perfectly well in 2003.

    The tables were there, but I noticed that sometimes the copying didn't work. As this didn't ever happen in debug mode, I added 5 secs waiting time right before the copying.

    This makes the macro slower, but as it takes a few minutes to run anyway, I didn't mind.

    Dim sngSec As Single 
    
        sngSec = Timer + 5
        Do While Timer < sngSec 
            DoEvents 
        Loop
    Last edited by Imardin; 05-04-2012 at 12:16 PM.

+ Reply to Thread

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