Changing picture layout in a macro

E

Eric

Hi all

I'm tryng to use a macro to paste an Excel chart as a picture into a Word document. Once it is pasted, I want to change its layout to "in line with text". When I try to do this while recording a macro, the "in line with text" option is greyed out

Any ideas to get around this

Thanks

Eric
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Eric > écrivait :
In this message, < Eric > wrote:

|| Hi all.
||
|| I'm tryng to use a macro to paste an Excel chart as a picture into a Word
document. Once it is
|| pasted, I want to change its layout to "in line with text". When I try
to do this while
|| recording a macro, the "in line with text" option is greyed out.
||

Look up the
ConvertToInlineShape
method in the VBA online help.

You may want to post your code so that people can have a look and help you
further if necessary.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

Eric

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:=Fals

Selection.ConvertToInlineShap

End Su

Do you have any further hints

Merci

Eric
 
J

Jean-Guy Marcil

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
 
E

Eric

Merci beaucoup! That does it!

Thank you for all the additional information. I will read through it and try to understand the logic better

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top