Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Changing image size proportionately

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lighthouse - 03 Jan 2005 21:24 GMT
I have an odd problem that seems like it shouldn't be a problem. Hoping
someone can help me with this.

I have some Word documents that may have images that need to be sized
programmatically. These docs are generated into Word through a
conversion from another application. The original application does not
have a reliable method of scaling the images. Consequently, some images
arrive in Word as HUGE! I noticed in Word that I could search for a
graphic (^g), open the "Format picture" dialog, click the "Size" tab,
then set the "width" to 6 inches while making sure that "Lock Aspect
Ratio" is checked.

Seemed like a good candidate for a macro, especially since I want to do
this automatically as part of the conversion process.

The problem is that I can not seem to resize these pictures
proportionately through VBA like I was able to do it manually. This
does not seem right since my understanding is that I should have MORE
control over my document w/ VBA rather than LESS.

When I recorded my actions as a macro then examined the code it showed
my height and width expressed as a no. of pixels. Since I want to limit
my images to 6 inches wide, 432 pixels is perfect (6 in. * 72 dpi).
However, I don't know the original dimensions of the images. I only
know that I don't want them displayed any wider than 6 inches.

Here is my code:

Public Sub testfind()
x = 0

g = ActiveDocument.InlineShapes.Count

For i = 1 To g
ActiveDocument.InlineShapes(i).Select
If Selection.InlineShapes(i).Width > 432# Then

Selection.InlineShapes(i).Line.Visible = msoFalse
Selection.InlineShapes(i).LockAspectRatio = msoTrue
Selection.InlineShapes(i).Width = 432
End If

Next i

End Sub

When I step through this w/ F8 it sets "g" to 58 and goes through the
IF statement once fine. When "i" is 2 the macro fails on the IF
statement. I get an error message that says: "The requested member of
the collection does not exist." This doesn't seem right since there are
58 members of the collection. Why does it fail on no. 2?

When I go to check InlineShape(1), which is >432, I find that the
height is still at the original dimension, even though I have
LockAspectRatio marked as checked. What is the magic incantation to
make the height change proportionately to the width that I've
specified? TIA
Klaus Linke - 04 Jan 2005 00:23 GMT
Hi,

It's pretty simple: You select the shape i (i=1, 2, ...) and then use Selection.InlineShapes(i).
Since you've selected one InlineShape, you always get an error except when i=1.

I don't really know why ".LockAspectRatio = msoTrue" doesn't work as you would expect it.
Something like the following seems to work:

Dim myIS As InlineShape

For Each myIS In ActiveDocument.InlineShapes
   With myIS
       If .Width > InchesToPoints(6) Then
           .Width = InchesToPoints(6)
           .ScaleHeight = .ScaleWidth
       End If
   End With
Next myIS

Regards,
Klaus

> I have an odd problem that seems like it shouldn't be a problem.
> Hoping someone can help me with this.
[quoted text clipped - 53 lines]
> make the height change proportionately to the width that I've
> specified? TIA
Lighthouse - 04 Jan 2005 13:23 GMT
Klaus, thanks very much. This worked EXACTLY as I had hoped. you saved
me much time and frustration. I didn't even know about the
"InchesToPoints() thing.

Lighthouse
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.