Bonjour,
Dans son message, < Eric > écrivait :
In this message, < Eric > wrote:
|| Merci, Jean-Guy! That looks like what I want.
||
|| I can look it up in the help, but when I try to run it, it gives me a
"Method or data member not
|| found" error.
||
|| My code is:
||
|| Sub PasteAsPicture()
||
|| Selection.PasteSpecial Link:=False,
DataType:=wdPasteEnhancedMetafile, _
|| Placement:=wdFloatOverText, DisplayAsIcon:=False
||
|| Selection.ConvertToInlineShape
||
|| End Sub
||
If you want to use your code you have to do something like:
'_______________________________________
Sub PasteAsPicture()
Dim MyRange As Range
Selection.PasteSpecial Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdFloatOverText, _
DisplayAsIcon:=False
Set MyRange = Selection.Paragraphs(1).Range
MyRange.ShapeRange(1).ConvertToInlineShape
Set MyRange = Nothing
End Sub
'_______________________________________
Because ConvertToInlineShape applies to a Shape object, not a Selection
object. When you get an error like that, select the method or property in
your code (Here it would be ConvertToInlineShape) and hit F1. It will take
you to the corresponding help page. Read it up, look at the examples and at
the top you have some blue words. Click on "Applies to" to see if you have
used it appropriately.
But, in your case, why don't you use this instead:
'_______________________________________
Sub PasteAsPicture()
Selection.PasteSpecial Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub
'_______________________________________
Much more direct!
But the first method I posted would allow you to selct the shape and
manipulate it further if it were needed to.
An even better way to manipulate the shape would be:
'_______________________________________
Sub PasteAsPicture()
'Declare the object variables
Dim MyRange As Range
Dim MyShape As Shape
'Paste the picture
Selection.PasteSpecial Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdFloatOverText, _
DisplayAsIcon:=False
'Set the range to the paragraph where the picture was pasted
Set MyRange = Selection.Paragraphs(1).Range
'Set the shape to the first shape in that range
'presumably the one just pasted
'If there were already some shapes anchored in that paragraph,
'then you would have to play with the number in
'ShapeRange(1) to grab the right shape
Set MyShape = MyRange.ShapeRange(1)
'Manipulate the shape
With MyShape
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
.Top = InchesToPoints(2)
.Left = InchesToPoints(2)
.ScaleHeight 1.5, msoTrue
.ScaleWidth 1.5, msoTrue
With .Line
.Weight = 3#
.DashStyle = msoLineSolid
.Style = msoLineSingle
.Transparency = 0#
.Visible = msoTrue
End With
End With
'Release the references
Set MyRange = Nothing
Set MyShape = Nothing
End Sub
'_______________________________________
But if you wanted to manipulate an inline shape, the code would be slightly
different:
'_______________________________________
Sub PasteAsPicture()
Dim MyRange As Range
Dim MyShape As InlineShape
Selection.PasteSpecial Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, _
DisplayAsIcon:=False
Set MyRange = Selection.Paragraphs(1).Range
Set MyShape = MyRange.InlineShapes(1)
With MyShape
.ScaleHeight = 125
.ScaleWidth = 125
With .Line
.Weight = 3#
.DashStyle = msoLineSolid
.Style = msoLineSingle
.Transparency = 0#
.Visible = msoTrue
End With
End With
Set MyRange = Nothing
Set MyShape = Nothing
End Sub
'_______________________________________
Good luck!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org