Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Selecting and replacing images in Footer (Word 2003)

    Hi,

    i have a document with logos (i think they're actually pictures) in the footer, one on the right and one on the left of the page, aligned with the inside and outside margins and with an absolute vertical position relative to the top of the page. The document has more than one section.

    I have a form with a command button which a user can use to select an image from disk, and then replace the left-hand logo in the section footers with the selected image.

    I have code that can replace a picture in a document with one selected by the user, but I am struggling with the header/footer aspect. I am specifically having difficulty after I have opened the header/footer view from the VB, and i want to select the contents of the footer and locate the left-hand image in the shapes (or Inlineshapes?) collection.

    Any code snips would be great.

  2. #2
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Selecting and replacing images in Footer (Word

    Here's a code snippet that seems to work for me. The only slightly dodgy bit is how to identify the left-hand image rather than the right-hand one.. at the moment I have replace the image using a hardcoded index into the InlineShapes collection.


    Sect.Footers(wdHeaderFooterPrimary).range.ShapeRan ge(1).delete
    Set oInlineShape = Selection.InlineShapes.AddPicture(FileName:=Me.lbl SubsLogoPath)

    'convert the picture to a shape
    Set oShape = oInlineShape.ConvertToShape

    'set the properties and position of shape
    oShape.AlternativeText = "Select a subcontrator logo using the Properties Dialog on the Proposal Toolbar"
    oShape.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    oShape.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
    oShape.Top = Application.CentimetersToPoints(24.5)
    oShape.Left = 0
    oShape.LockAspectRatio = msoTrue

    'only limit the size if it is too big and warn the user to resize manually first
    'the aspect ratio is locked in any event
    If oShape.Height > Application.CentimetersToPoints(1.25) Then
    oShape.Height = Application.CentimetersToPoints(1.25)
    sizeChanged = True
    End If
    If oShape.Width > Application.CentimetersToPoints(4) Then
    oShape.Height = Application.CentimetersToPoints(4)
    sizeChanged = True
    End If

    If sizeChanged Then
    Call MsgBox("The size of the selected image has been automatically resized because it was too big!" _
    & vbLf & "The maximum size is 20x75 points or xxx by xxx cm.", vbExclamation, "Error")
    End If

    Else
    MsgBox "No images found in the footer - check the template!", vbCritical, "Image not Found"
    End If


    'close the headerfooter view and return to main document
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Posting Permissions

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