1
我有一些在Word 2003中開發的第三方代碼,但它在Word 2010中不工作。 代碼應該粘貼一個Excel.Chart對象並將其轉換爲內聯形狀。Word 2010 VBA粘貼Excel圖表對象
Sub PasteChartAsInteractive(chart As Excel.chart)
Dim myShape As Shape
chart.ChartArea.Copy
Selection.Style = ActiveDocument.Styles("Normal")
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.PasteAndFormat (wdChart)
Set myShape = Selection.Paragraphs(1).range.InlineShapes(1).ConvertToShape
myShape.ConvertToInlineShape
...
起初,PasteAndFormat
系引發一個空的錯誤消息。
我又試圖替換該行以
Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
:=wdInLine, DisplayAsIcon:=False
而且它提出了另外一個錯誤,說System Error &H80004005 (-2147467259). Unspecified error
。但在這種情況下,圖表實際上粘貼到Word中。
有人知道是什麼原因導致問題以及應該如何解決?
TIA
可能是Word和Excel'選擇'類型越來越搞砸了。嘗試定義一個'Word.Selection'對象,並在當前設置'Selection'時設置它的變量。 –
沒有運氣。相同的錯誤消息,對於兩個粘貼代碼。 – Milan
嗯。你根本沒有在你的代碼中有[UserForm](http://support.microsoft.com/kb/230888),是嗎?並且沒有原始錯誤消息的信息 - 根本沒有代碼或文本? –