Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Textbox/Picture Sizing using VB (WORD 97/2000)

    Hi,

    I have a WORD template that contains a front cover. The front cover has a backdrop and document information (title, issue, status etc) on it.

    The size of the backdrop (jpeg file) must change (company edict) depending on the paper size, i.e. it is longer for A4 and smaller for US Letter. At the moment I have added the image in a textbox but I do not know how to get hold of the picture under VB so that I can change the height of it depending on the paper size. Also, why can't I make the header on the first (front cover) oage to be the same size to be bigger than about half a page?

    Thanks for the response in advance.

    Regards

    Robie
    Thanks.
    Robie

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    I don't have answers for all your questions, but... why do you need such a big header? One of the attractions of textboxes, frames, and floating pictures is that they can be positioned arbitrarily, regardless of the size of the header. (In one template, I have a frame in the "header" that actually prints superimposed on the footer.)

    In VBA, you would be working with the Shape and ShapeRange objects, which can be accessed through the relevant Range. In this case, the relevant Range might be the Section 1 First Page Header. It's something that I'm sure you'll find with a bit of trial and error. Or you could post a sample document, sensitive stuff expunged.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    I echo Jefferson's question why you would want a header of more than half the page height. But it is possible, just increase the top margin of the page far enough.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    Hi Robie,

    If your picture has a horizontal area that is all the one shade, you could consider using two images - one aligned with the top of the page and one aligned with the bottom, so that they overlap on the shorter formats. This would obviate the need for any vba at all.

    If you really do need a vba solution, to stretch/compress the image's width & height, you could try something based on:

    <pre>Sub Reformat()
    On Error Resume Next
    For i = 1 To ActiveDocument.Shapes.Count
    ActiveDocument.Shapes(i).Select
    With Selection.ShapeRange
    .ScaleHeight 0.7, True
    .ScaleWidth 0.7, True
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    .Left = wdShapeCenter
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .Top = wdShapeCenter
    .LockAnchor = True
    With .WrapFormat
    .AllowOverlap = False
    .Side = wdWrapBoth
    .DistanceTop = CentimetersToPoints(0)
    .DistanceBottom = CentimetersToPoints(0)
    .DistanceLeft = CentimetersToPoints(0)
    .DistanceRight = CentimetersToPoints(0)
    .Type = wdWrapSquare
    End With
    End With
    Next i
    MsgBox "Finished Reformatting."
    End Sub
    </pre>


    Cheers
    PS: The above macro nominally sets the picture to 70% of full size.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    Thanks to you all for your responses. You all are great for people like us. A BIIIIIIIIIIIIIIG THANK YOU.

    I am using VBA to change the height of the text box when ever the paper type changes from A4 to US Letter & vice-versa.
    Thanks.
    Robie

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    Hi Robie,

    Here's something a bit more automatic, for a single shape that isn't in-line with text:

    <pre>Sub AutoSize()
    Dim DeltaWidth As Single, DeltaHeight As Single
    Dim oPgWidth As Single, oPgHeight As Single
    Dim oShpWidth As Single, oShpHeight As Single
    With ActiveDocument
    oPgWidth = .PageSetup.PageWidth
    oPgHeight = .PageSetup.PageHeight
    .Shapes(1).Select
    With Selection.ShapeRange
    .ScaleHeight 1, True
    .ScaleWidth 1, True
    oShpWidth = Selection.ShapeRange.Width
    oShpHeight = Selection.ShapeRange.Height
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
    .Left = wdShapeCenter
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .Top = wdShapeCenter
    If oShpWidth <> oPgWidth Then
    DeltaWidth = (oPgWidth / oShpWidth)
    .ScaleWidth DeltaWidth, True
    End If
    If oShpHeight <> oPgHeight Then
    DeltaHeight = (oPgHeight / oShpHeight)
    .ScaleHeight DeltaHeight, True
    End If
    End With
    End With
    End Sub
    </pre>

    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Textbox/Picture Sizing using VB (WORD 97/2000)

    Wow. Thanks. That is just what I needed. You guys are just brilliant. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    Thanks.
    Robie

Posting Permissions

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