Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Format Picture Macro

132 views
Skip to first unread message

Raymond O'Neill

unread,
Mar 3, 2005, 3:51:16 PM3/3/05
to
Hi!

I'm having trouble recording a macro that formats pictures inserted from
file.
The macro stops and the debugger takes me to this line:
Selection.InlineShapes(1).Left = 0#

Also, how can I make a macro to insert picture from file that allows the
user to select a file and then continues with the macro inserting and
formating the picture?

Thanks!


Jay Freedman

unread,
Mar 3, 2005, 5:35:28 PM3/3/05
to

Hi Raymond,

The trouble with the code you quoted is that an InlineShape is treated like
a single character, and therefore it doesn't have a .Left property. You need
to insert the picture as a floating object, a Shape, instead of an
InlineShape. This isn't something you can record.

To answer your second question, the preferred method is to call Word's
built-in Insert Picture dialog (see
http://word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htm). If the user selects a
picture and clicks OK instead of Cancel, then you can insert the picture as
a Shape and format it. Have a look at this code:

Sub Macro1()
Dim strFile As String
Dim oShape As Shape

' use the built-in dialog to let user
' choose the picture
With Dialogs(wdDialogInsertPicture)
If .Display <> -1 Then Exit Sub
strFile = .Name
End With

' insert the picture floating with the anchor
' at the top-left corner of the paragraph that
' contains the cursor
Set oShape = ActiveDocument.Shapes.AddPicture _
(FileName:=strFile, _
Anchor:=Selection.Range)

' format the picture as desired
With oShape
.WrapFormat.Type = wdWrapSquare
.Left = 0 ' at left margin
.Width = InchesToPoints(2.25)
' etc...
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


0 new messages