Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resizing, inserting pictures into columns (Word 2002)

    I am working an an approx. 300-400 page report in which pictures (jpeg) have to be:resized and inserted into three columns with filename above picture. Pictures are stored in several folders. Is there a macro available for this?

    Thanks so very much for your help.

    Idella

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Resizing, inserting pictures into columns (Word 2002)

    Hi Idella:
    I don't have a macro for this, but I thought I'd let you know one technique, depending upon how many graphics you have. If you create a 3 column table, you can place the captions in one row, then the pictures in the next row (1 per cell). If you size every other row the size that you want for the pictures, you can then go to Table/Properties... On the table tab, click the Options button & UNcheck "Automatically resize to fit contents". This will force the picture to resize to fit inside the cell.
    Hope this helps,

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Resizing, inserting pictures into columns (Word 2002)

    This code extracted from a larger routine should get you started

    <pre> 'Now perform the search
    With Application.FileSearch
    .LookIn = sDir
    .FileName = sFileType
    .SearchSubFolders = Me.ChkIncSubdir.Value
    .Execute
    If .FoundFiles.count > 0 Then
    'Speed up macro by not redrawing each picture
    ActiveWindow.View.ShowPicturePlaceHolders = True

    For i = 1 To .FoundFiles.count
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.InlineShapes.AddPicture FileName:=.FoundFiles(i), _
    LinkToFile:=False, SaveWithDocument:=True
    Selection.Paragraphs(1).Style = wdStyleHeading3
    If Me.ChkIncName = True Then
    Selection.TypeParagraph
    Selection.TypeText text:=.FoundFiles(i)
    Selection.Paragraphs(1).Style = wdStyleNormal
    End If
    Selection.TypeParagraph
    Next i
    'Downsize graphics as required
    If Me.ResizeCB.Value <> "" Then
    iSize = Val(Me.ResizeCB.Value)
    With ActiveDocument
    For i = 1 To .InlineShapes.count
    If .InlineShapes(i).Height > CentimetersToPoints(iSize) Or _
    .InlineShapes(i).Width > CentimetersToPoints(iSize) Then
    If .InlineShapes(i).Height > .InlineShapes(i).Width Then
    .InlineShapes(i).Height = CentimetersToPoints(iSize)
    .InlineShapes(i).ScaleWidth = .InlineShapes(i).ScaleHeight
    Else
    .InlineShapes(i).Width = CentimetersToPoints(iSize)
    .InlineShapes(i).ScaleHeight = .InlineShapes(i).ScaleWidth
    End If
    End If
    Next i
    End With
    End If
    'Move to top of file and show graphics
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.View.ShowPicturePlaceHolders = False
    End Select</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    New Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Resizing, inserting pictures into columns (Word 2002)

    Thank you so much for your response and the technique you gave. This is very helpful to me.

  5. #5
    New Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Resizing, inserting pictures into columns (Word 2002)

    Thank you for responding to my question. Is this a macro that I can copy and paste into Visual Basic? Do I enter a number for the picture height and width where it says (iSize)?

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Resizing, inserting pictures into columns (Word 2002)

    I have modified the code to make it easier for you to get it going. You are now prompted for information that the other version took from a user form.

    You will be able to paste this into Word and then copy it again and paste it into the VBA environment (the middle step preserves the line breaks).
    <pre>Sub temp1()
    Dim iSize As Single, i As Integer
    With Application.FileSearch
    .LookIn = InputBox("Type the file path", "Directory", "C:")
    .FileName = InputBox("What file type is being inserted", "File Types", "*.jpg")
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.count > 0 Then
    'Speed up macro by not redrawing each picture
    ActiveWindow.View.ShowPicturePlaceHolders = True
    For i = 1 To .FoundFiles.count
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.InlineShapes.AddPicture FileName:=.FoundFiles(i), _
    LinkToFile:=False, SaveWithDocument:=True
    Selection.Paragraphs(1).Style = wdStyleHeading3
    Selection.TypeParagraph
    Selection.TypeText text:=.FoundFiles(i)
    Selection.Paragraphs(1).Style = wdStyleNormal
    Selection.TypeParagraph
    Next i
    End If
    End With

    'Downsize graphics as required
    iSize = Val(InputBox("What is the maximum size for graphics in cm?", "Graphic Size"))
    With ActiveDocument
    For i = 1 To .InlineShapes.count
    If .InlineShapes(i).Height > CentimetersToPoints(iSize) Or _
    .InlineShapes(i).Width > CentimetersToPoints(iSize) Then
    If .InlineShapes(i).Height > .InlineShapes(i).Width Then
    .InlineShapes(i).Height = CentimetersToPoints(iSize)
    .InlineShapes(i).ScaleWidth = .InlineShapes(i).ScaleHeight
    Else
    .InlineShapes(i).Width = CentimetersToPoints(iSize)
    .InlineShapes(i).ScaleHeight = .InlineShapes(i).ScaleWidth
    End If
    End If
    Next i
    End With
    ActiveWindow.View.ShowPicturePlaceHolders = False
    End Sub</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •