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:
I recieve a an error message saying: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
"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
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.
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
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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks