Hi!
On a userform I have a commandbutton which opens the wdDialogsInsertPicture.
The cursor is within a table with either one or two cells (the document can
have several pages, and the pages has a table with either one cell or two
cells), and the picture is inserted where the cursor is. So far so good, BUT
- I want the inserted picture to have certain formatproperties. In the code
below "ActiveDocument.Shapes(1).Select" I need to be able to select the
picture that what just inserted, but it selects the first picture in the
dokument instead. The newly inserted pictures isn't always the first or the
last picture that was inserted in the doucment, so I can't count to the last
inserted picture either.
Is there anyone who have some suggestions for how to deal with this? (And
save me from more sleepless nights :-) )
Lot of thanks from Mette
-------------
If Selection.Information(wdWithInTable) Then
With Dialogs(wdDialogInsertPicture)
If .Show Then
ActiveDocument.Shapes(1).Select 'This is where the problem is.
With Selection.ShapeRange
.LockAspectRatio = msoTrue
.Width = 150
.Left = wdShapeRight
.WrapFormat.Type = wdWrapSquare
.WrapFormat.Side = wdWrapLeft
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End If
End With
End If
--
Jean-Guy Marcil - 01 Dec 2004 14:03 GMT
MetteHD was telling us:
MetteHD nous racontait que :
> Hi!
>
[quoted text clipped - 12 lines]
> Is there anyone who have some suggestions for how to deal with this?
> (And save me from more sleepless nights :-) )
As you have found out,
ActiveDocument.Shapes(1).Select
means the first shape in the document.
Always try to define a range when working with specific area of the
document, then
SomeRange.Shapes(1).Select
means the first shape in the range you define.
You can also use range objects, like:
Selection.Cells(1).Range.Shapes(1).Select
The first shape in the current cell
etc.
Avoid using the Select method unless absolutely necessary.
Also, do you know for a fact that all shapes will be inserted as floating?
You may have to test for that.
Finally, if they are inline shapes, just setting one dimension will distort
the shape, even with LockRatio set to true.
See the code below for examples of the above.
'_______________________________________
Dim Myrange As Range
Dim MyWidth As Long
Const FixWidth As Long = 150
If Selection.Information(wdWithInTable) Then
With Dialogs(wdDialogInsertPicture)
If .Show Then
Set Myrange = Selection.Cells(1).Range
If Myrange.InlineShapes.Count > 0 Then
With Myrange.InlineShapes(1)
.LockAspectRatio = msoTrue
MyWidth = .Width
.Width = FixWidth
.Height = .Height * (FixWidth / MyWidth)
End With
Myrange.ParagraphFormat.Alignment = wdAlignParagraphRight
Else
With Myrange.ShapeRange
.LockAspectRatio = msoTrue
.Width = FixWidth
.Left = wdShapeRight
.WrapFormat.Type = wdWrapSquare
.WrapFormat.Side = wdWrapLeft
End With
End If
End If
End With
End If
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Word Heretic - 05 Dec 2004 00:58 GMT
G'day "MetteHD" <MetteHD@discussions.microsoft.com>,
<Sighs> I haven't looked at this sorta stuff for a long while so bear
with me please. I think if you remove the line where the problem is,
you will have your selection as the dialog defaults to inserting the
picture at the selection point. You are destroying that by forcing a
selection of something else.
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
MetteHD reckoned:
>Hi!
>
[quoted text clipped - 33 lines]
>
> End If
Ray ;) - 31 Mar 2005 22:49 GMT
Hi I am working with word automation too. And also I insert some pictures, if
u want to have access to the shape's propieties u should use something like
this :
Dim PicShape as word.shape
set PicShape = m_objDocument.Shapes.AddOLEObject(Anchor:=Selection.Range,
ClassType:="DIYPhoto.Object", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False)
So with this code just use PicShape as ur object. Now just type
PicShape.name = ""
or PicShape.Height = 100 and so on.
I hope this works for you :)
> Hi!
>
[quoted text clipped - 33 lines]
>
> End If