PDA

View Full Version : Paste Excel PivotChart into Word gives 5941 error



Dunro
10-19-2012, 10:45 AM
Hi everyone,

I'm not really great with Word VBA (more used to Access and Excel..).

I have a template document which has a bunch of bookmarked ranges. The macro ultimately deletes each bookmark and pastes in the correct data. The bookmark aspect of this macro shouldn't be impacting the function below.

Stepping through the module produces a 5941 "The requested member of the collection does not exist." error at "wrdApp.Selection.Paste" -- however, looking at the document itself, the chart was pasted in just fine.


Private Function PasteGraphIntoDoc(wrdApp As Word.Application, currentSheet As Excel.Worksheet) As Long
' Pastes graph, then lets the calling function know the new end of the range.
On Error GoTo Exit_Error

currentSheet.Activate
currentSheet.Cells(1, 1).Select
currentSheet.ChartObjects(1).Copy

If wrdApp.Selection.Tables.Count = 1 Then
wrdApp.Selection.Tables(1).Select ' make sure entire table is selected/deleted when necessary.
End If

'wrdApp.Selection.Delete ' delete existing selection. Disabled until I figure out error below.
wrdApp.Selection.Paste ' ** this line causes the error.
wrdApp.Selection.InlineShapes(1).LinkFormat.BreakLink


PasteGraphIntoDoc = wrdApp.Selection.Range.End

Exit_Error:
Stop
Resume Next
End Function


Any ideas?