#1   Report Post  
Raymond O'Neill
 
Posts: n/a
Default Format Picture Macro

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!


  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Raymond O'Neill wrote:
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!


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


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert text over a picture without losing the picture? PMD Microsoft Word Help 1 February 4th 05 05:06 AM
MS Word Picture Object tj Microsoft Word Help 0 January 26th 05 03:09 AM
Save As is not working due to macro security settings Craig Meritz Microsoft Word Help 1 December 16th 04 03:53 AM
Edit picture works on some and not on other pictures. Why? Harley59 Microsoft Word Help 1 December 12th 04 06:37 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 11:52 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"