PDA

View Full Version : Format of an object located in clipboard



shimuno
08-26-2008, 06:26 AM
Hello

I have designed two macros allowing the user to paste and format excel tables (macro number one) and excel charts (macro number (two) in a word document. The user must copy the excel object and then use the macros.

I use the following code to paste an excel table :
Selection.PasteExcelTable False, False, False

And I use this to paste an excel chart :
Selection.PasteAndFormat (wdPasteDefault)

Here is my problem : the macro do not work if the user select an excel chart and try to paste it by using the macro designed for an excel table (likewise, he cannot select an excel table and paste it with the macro designed for an excel chart).

Could you please help me with this one ? Maybe, I could try to retrieve the type of object located in the clipboard, but I do not know the appropriate instructions.

Thank you very much for your help.

Nelviticus
08-27-2008, 07:18 AM
When you say the macro does not work, do you mean that it gives an error or that it pastes, but pastes wrongly?

If it gives an error, you could use something like this:
Public Sub PasteExcel()
Dim TriedTable As Boolean
Dim TriedChart As Boolean
TriedTable = False
TriedChart = False
PasteTable:
On Error GoTo PasteChart
If Not TriedTable Then
TriedTable = True
Selection.PasteExcelTable False, False, False
End If
GoTo Finish
PasteChart:
On Error GoTo PasteTable
If Not TriedChart Then
TriedChart = True
Selection.PasteAndFormat (wdPasteDefault)
End If
GoTo Finish
Finish:
Exit Sub
End Sub
Regards

shimuno
08-27-2008, 08:59 AM
Thank you, it works perfectly.