Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Select and Size Charts with code! (Word 2000 >)

    Hi all,

    I'm trying to help a friend that recieves report based documents that contain multiple charts. The charts are just slapped into the documents and very offten they are different sizes. I would like to get some assistance from the pro's in this forum as my VBA knowledge in word is quite limited.

    I include a faked attachment that simulates the scenario. In this doc, I need the coded macro to select each chart and size the height to 2" (2 inches). Istarted recording a macro, and used the Obj. Browser to navigate to the charts, but I'm not sure how to select them. I used the properties dialog to size the charts.

    Could someone guide me in the right direction....Words VBA is not as user friendly as Excel VBA!!!!
    Attached Files Attached Files
    Regards,
    Rudi

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

    Re: Select and Size Charts with code! (Word 2000 >)

    Whether Word VBA is more or less friendly as Excel VBA is mostly a matter of what you're familiar with. For someone who has programmed a lot in Word, Excel VBA is very alien in the beginning, and vice versa.

    Here is a macro that will set the height of all inline picture objects to 2". It doesn't change the width, i.e. it doesn't preserve aspect ratio:

    Sub SizeCharts()
    Dim sh As InlineShape
    For Each sh In ActiveDocument.InlineShapes
    If sh.Type = wdInlineShapePicture Then
    sh.Height = InchesToPoints(2)
    End If
    Next sh
    Set sh = Nothing
    End Sub

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Select and Size Charts with code! (Word 2000 >)

    Hans, this will work well. The charts height to width ratio is always going to be the same. I can add a width property in your code and simply calculate the width if the height is 2".

    One other question. I assume this will select all inline objects. Is there a way to distinguish charts from other inline objects such as pictures or tables, etc. Ideally I only need the charts to be sized...not other items?

    TIA
    Regards,
    Rudi

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

    Re: Select and Size Charts with code! (Word 2000 >)

    The charts in your sample document are of type wdInlineShapePicture. The code tsts for this type, and resizes only inline pictures, not other inline shapes.

    There is no way to distinguish the charts from other pictures. It would have been possible if they had been inserted as Excel objects.

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Select and Size Charts with code! (Word 2000 >)

    OK, thats good enough....many thanx
    Regards,
    Rudi

Posting Permissions

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