Question : Word Macro problem, dynamic image resize macro

We are trying to resize an image so that it expands the image to the size of the document.  The macro below works, but it only works because i have commented out the "'ActiveDocument.PageSetup.TopMargin - ActiveDocument.PageSetup.BottomMargin" and the "ActiveDocument.PageSetup.LeftMargin - ActiveDocument.PageSetup.RightMargin" sections.  I would like it to be completely dynamic so that i dont have to use the hard coded 180 and 90 values.

We are using office 2003 service pack 2.


This works, but i have to comment out the rest of the dynamic values(arggh):

For Each ishape In ActiveDocument.InlineShapes
        With ishape
        ' make the image as large as page size
       
        ishape.Height = ActiveDocument.PageSetup.PageHeight - 180 'ActiveDocument.PageSetup.TopMargin - ActiveDocument.PageSetup.BottomMargin
        ishape.Width = ActiveDocument.PageSetup.PageWidth - 90 'ActiveDocument.PageSetup.LeftMargin - ActiveDocument.PageSetup.RightMargin
        'ishape.Type = wdInlineShapeLinkedPicture
        ' SavePictureWithDocument = False
        'ishape.Select
        'ishape.LinkFormat.SavePictureWithDocument = False
        ' add a pagebreak before each image
        'Selection.MoveUp Unit:=wdLine, Count:=1
        'Selection.InsertBreak Type:=wdPageBreak
        End With
    Next ishape ' get the next shape and go back thru the loop again

Answer : Word Macro problem, dynamic image resize macro

A Section is a Word concept. It is used to separate portions of a Document that need different page formatting. If, for instance, you need some of the document in portrait orientation, and some in landscape, you would need to have them in different sections, divided by a Section break.

In the Word user interface, the sections can be set up separately from the menu File/Page Setup... If you do have more than one section in your document, the 'Apply to:' dropdown will include a 'This section' choice.

This code treats each section separately:

Sub ExpandInLineShapes()
    Dim iShape As InlineShape
    Dim sec As Section
   
    For Each sec In ActiveDocument.Sections
        For Each iShape In sec.Range.InlineShapes
            With iShape
            ' make the image as large as page size
           
            iShape.Height = sec.PageSetup.PageHeight - sec.PageSetup.TopMargin - sec.PageSetup.BottomMargin
            iShape.Width = sec.PageSetup.PageWidth - sec.PageSetup.LeftMargin - sec.PageSetup.RightMargin
            End With
        Next iShape
    Next sec
End Sub
Random Solutions  
 
programming4us programming4us