This code will run in Word 2003 but not 2007.

B

BRC

Hi All,
I put a post about this problem up yesterday but I think I may not
have been to clear about the problem and what I was trying to do. I
have resolved most of my problems but I still have an issue with the
code below. When I run this in Word 2003 it works perfectly and
inserts a picture into the document at the cursor location. However,
when I try it in Word 2007 I get an error that says “The method or
Property is not available because the current selection is not a
graphic”. (I am trying to insert a photo usually a jpeg.). The
debugger highlights the line **With Dialogs(wdDialogFormatPicture)**
Obviously I user of both 2003 and 2007 versions of Word. Any advice
would be greatly appreciated.

**********************************************
Sub InsertPic()
'
If Dialogs(wdDialogInsertPicture).Show <> 0 Then
'''resizes the shape
Selection.Paragraphs(1).Range.InlineShapes(1).Select
With Dialogs(wdDialogFormatPicture)
.ScaleX = 28
.ScaleY = 18
.Execute
End With
End If
End Sub
*********************************************
 
L

Leonid N

I had similar problem posted on 14 Apr under subject "FormatPicture in
Word.Basic API does not work in Word 2007".

Later I found a bypass and posted it, look into the thread for details.
 
G

Graham Mayor

The problem arises because of the different way that graphics are handled in
Word 2007 native document format. The following however should work in
either version and does what your macro purports to do - though if you want
all the images to be the same height and width, it might be better if you
set the height and width rather than scale the original as in the second
example:

Sub InsertPic()
If Dialogs(wdDialogInsertPicture).Show <> 0 Then
With Selection.Paragraphs(1).Range.InlineShapes(1)
.LockAspectRatio = msoFalse
.ScaleHeight = 18
.ScaleWidth = 28
End With
End If
End Sub

Sub InsertPic()
If Dialogs(wdDialogInsertPicture).Show <> 0 Then
With Selection.Paragraphs(1).Range.InlineShapes(1)
.LockAspectRatio = msoFalse
.Height = CentimetersToPoints(0.98)
'or use InchesToPoints
.Width = CentimetersToPoints(1.75)
End With
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

BRC

The problem arises because of the different way that graphics are handledin
Word 2007 native document format. The following however should work in
either version and does what your macro purports to do - though if you want
all the images to be the same height and width, it might be better if you
set the height and width rather than scale the original as in the second
example:

Sub InsertPic()
    If Dialogs(wdDialogInsertPicture).Show <> 0 Then
        With Selection.Paragraphs(1).Range.InlineShapes(1)
            .LockAspectRatio = msoFalse
            .ScaleHeight = 18
            .ScaleWidth = 28
        End With
    End If
End Sub

Sub InsertPic()
    If Dialogs(wdDialogInsertPicture).Show <> 0 Then
        With Selection.Paragraphs(1).Range.InlineShapes(1)
            .LockAspectRatio = msoFalse
            .Height = CentimetersToPoints(0.98)
            'or use InchesToPoints
            .Width = CentimetersToPoints(1.75)
        End With
    End If
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>





- Show quoted text -

Thank You Graham, That was exactly what I was looking for.
Brilliant.
Thanks again.
 

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