Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I insert text over a picture without losing the picture? | Microsoft Word Help | |||
MS Word Picture Object | Microsoft Word Help | |||
Save As is not working due to macro security settings | Microsoft Word Help | |||
Edit picture works on some and not on other pictures. Why? | Microsoft Word Help | |||
2000 to 2002 macro and "Could not open macro storage" | Mailmerge |