PasteSpecial from Excel to Word then format the object help

nguyen_tri

New Member
Joined
Oct 17, 2017
Messages
9
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.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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.
I am missing the End if above the End With, but still the code does not recognize the object. Please help me.
 
Upvote 0
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:
Code:
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
 
Upvote 0
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
 
Upvote 0
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.
 
Last edited:
Upvote 0
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?
Code:
 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.
 
Last edited:
Upvote 0
With the code I supplied in post #4 , simply insert:
.ConvertToInlineShape
between End If and End With.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top