# PasteSpecial from Excel to Word then format the object help



## nguyen_tri (Oct 19, 2017)

Hi I am trying to paste special an object from Excel to the word file. However, I get "member or data member not found". Here is my code:
With Selection.Tables(1).Rows(1)
    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
        Selection.Object (1)
        If Object(1).Height > 150# Then
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.ScaleWidth 0.95, msoFalse
        .ShapeRange.ScaleHeight 1.03, msoTrue
        Else
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.ScaleWidth 0.95, msoFalse
        .ShapeRange.ScaleHeight 0.75, msoTrue
    End With

What am I doing wrong here? I think the problem is I don't know how to get the object's name. Thank you so much.


----------



## nguyen_tri (Oct 19, 2017)

nguyen_tri said:


> Hi I am trying to paste special an object from Excel to the word file. However, I get "member or data member not found". Here is my code:
> With Selection.Tables(1).Rows(1)
> Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
> wdInLine, DisplayAsIcon:=False
> ...


I am missing the End if above the End With, but still the code does not recognize the object. Please help me.


----------



## nguyen_tri (Oct 19, 2017)

Help me guys !!!!!!!!


----------



## Macropod (Oct 19, 2017)

A little patience wouldn't go astray...

Your code has some fundamental problems. For starters, you'd pasting with:
Placement:=wdInLine
but then trying to address the pasted content as:
Selection.Object (1)
despite .Object (1) not being a valid Selection property - which using intellisense would have told you - then you're trying to address the inlineshape you've pasted via:
Placement:=wdInLine
using:
.ShapeRange
which isn't an inlineshape property, either. It looks to me rather like you've just thrown this code together without any regard for the Word VBA object model, then wondered why it doesn't work.

Try:

```
With ActiveDocument.Tables(1).Range.Cells(1).Range
  .PasteSpecial Link:=True, DataType:=wdPasteOLEObject, _
    Placement:=wdFloatOverText, DisplayAsIcon:=False
  With .ShapeRange(1)
    .LockAspectRatio = msoFalse
    .ScaleWidth 0.95, msoFalse
    If .Height > 150# Then
      .ScaleHeight 1.03, msoTrue
    Else
      .ScaleHeight 0.75, msoTrue
    End If
  End With
End With
```


----------



## nguyen_tri (Oct 19, 2017)

Thank you so much. I'm learning VBA currently. The name of the object should be InlineShapes, but somehow the macro could not find the object. Here is my code now:
 With Selection.Tables(1).Rows(1)
    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
    With .InlineShapes(1)
    .LockAspectRatio = msoFalse
    InlineShapes(1).ScaleWidth = 95
     If .Height > 150# Then
      .ScaleHeight 103, msoTrue
    Else
      .ScaleHeight 75, msoTrue
    End If
    End With
    End With


----------



## Macropod (Oct 19, 2017)

nguyen_tri said:


> I'm learning VBA currently.


Apparently not. You've ignored most of what I said in my previous reply, including the fully-functional code I posted...

When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.


----------



## nguyen_tri (Oct 20, 2017)

I used your code to post the object in as a Shaperange, but it still does not work. I want to paste it as an InlineShape. Can you check my code now?
	
	
	
	
	
	



```
With Selection.Tables(1).Range.Cells(1).Range    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
    With .InlineShapes(1)
    .LockAspectRatio = msoFalse
    .ScaleWidth = 95
    If .Height > 150# Then
      .ScaleHeight = 103
    Else
      .ScaleHeight = 75
    End If
  End With
    End With
```
It showed error at With .Inlineshapes(1). The debug tells me that the data type is unavailable.


----------



## Macropod (Oct 20, 2017)

With the code I supplied in post #4 , simply insert:
.ConvertToInlineShape
between End If and End With.


----------



## nguyen_tri (Oct 20, 2017)

Thank you so much. It works perfectly now.


----------

