atw: Re: "Getting to grips with VBA basics in 15 minutes".

  • From: Ilana Cohney <ilana.cohney@xxxxxxxxxxxxxxxxxx>
  • To: austechwriter@xxxxxxxxxxxxx
  • Date: Fri, 06 Aug 2004 12:29:26 +1000

Talking about VB code, I have some code that is meant to resize 
screenshots so that they fit within a preset size.  I can not get it to 
work.  The debugger always stops on the Selection.InlineShapes line. For 
some reason, it will only work if a graphic is selected, but this would 
defeat the purpose of the macro.   Is there anyone out there is would 
like to have a look at the code and see what is wrong with it.  If we 
could get it to work, this would be a very useful macro for all of us.
Here it is:
Sub ASI_ResizeScreenshot()
' Resizes all graphics to fit into page width and height.
            Dim MaxHeight As Double
            Dim MaxWidth As Double
            Dim NewHeight As Double
            Dim NewWidth As Double
            Dim ScaleBy As Double
                      
'            MaxHeight = InchesToPoints(6.5) 'Change target dimensions here.
'            MaxWidth = InchesToPoints(5.75)
            MaxHeight = CentimetersToPoints(15) 'Change target 
dimensions here.
            MaxWidth = CentimetersToPoints(12)
            ScaleBy = 1 ' Start at 100%
         
            Selection.InlineShapes(1).LockAspectRatio = msoFalse
            Selection.InlineShapes(1).Reset
            With Selection.InlineShapes(1)
                NewWidth = .Width
                NewHeight = .Height
                Do While NewWidth >= MaxWidth Or NewHeight >= MaxHeight 
'...still too big
                    ScaleBy = ScaleBy - 0.01    ' Reduce scale by one 
percentage point.
                    NewWidth = .Width * ScaleBy
                    NewHeight = .Height * ScaleBy
                Loop
                .Width = NewWidth
                .Height = NewHeight
            End With
End Sub     '_________________________

All the best
Ilana
**************************************************
To post a message to austechwriter, send the message to 
austechwriter@xxxxxxxxxxxxxx

To subscribe to austechwriter, send a message to 
austechwriter-request@xxxxxxxxxxxxx with "subscribe" in the Subject field.

To unsubscribe, send a message to austechwriter-request@xxxxxxxxxxxxx with 
"unsubscribe" in the Subject field.

To search the austechwriter archives, go to 
www.freelists.org/archives/austechwriter

To contact the list administrator, send a message to 
austechwriter-admins@xxxxxxxxxxxxx
**************************************************

Other related posts: