+ Reply to Thread
Results 1 to 5 of 5

Macro to return the height and width of an object in the clipboard

  1. #1
    Registered User
    Join Date
    08-27-2003
    Location
    Perth, Australia
    MS-Off Ver
    2000
    Posts
    47

    Macro to return the height and width of an object in the clipboard

    I would like a macro that returns the width and height of an excel chart copied as a picture to the clipboard.

    The reason I want to do this is that I want to paste pictures into textboxes in Word and ensure consistency of appearance. So, I’ll set the width of each textbox to a full text column width, adjust the pasted picture’s width to slightly less than the width of the box (maintaining aspect ratio so it doesn’t distort), then set the height of the textbox to a little bit more than the new height of the picture inside it.

    So, in order to set the textbox’s size I’d like to know the dimensions of the picture to go inside it before it’s pasted.

    Apologies if this looks more like a Word than Excel question
    Nicky

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485
    Not sure you can get the dimensions once on the clipboard.

    If you know what object was copied you can get the dimensions of the object.

    When you say paste into textboxes do you actually mean place the pasted chart over the area occupied by the textbox? If so can you not just resize the pasted object in Word?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-27-2003
    Location
    Perth, Australia
    MS-Off Ver
    2000
    Posts
    47
    Thanks Andy

    I want a macro to standardise the appearance of charts in documents with lots of them: the same width of charts in a textbox, the textbox taking the full width of the column but no more. I also want to apply standard wrapping, positioning, margins, captions etc to the textboxes.

    Because I have several staff contributing to documents, with varying Excel and Word capabilities, a single macro to do all these things will make life much easier in standardising documents’ appearance.

    I have already created a macro to do this for one set of documents we produce using templates which fix the column width in Word and chart size in Excel.

    However, other Word document templates we use have different margins and import charts with different dimensions.

    In order to create a similar macro, I was hoping to
    • set the textbox width equal to the text column width, resize the chart’s width so it just fits in the textbox (but keeping the aspect ratio fixed so it doesn’t distort),
    • then set the textbox’s height to accommodate the height of the chart plus space for the caption. This is the point at which I need the chart’s height and width, or at least their ratio.
    I could resize the textbox and chart after pasting, but have found that gets messy if the source chart is much smaller or larger than the textbox it’s pasted into.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485
    So if your code is copying the chart to the clipboard you can determine the dimensions of the chart object, yes?

  5. #5
    Registered User
    Join Date
    08-27-2003
    Location
    Perth, Australia
    MS-Off Ver
    2000
    Posts
    47
    Hi Andy

    I hadn't thought if that - I've been using one set of macros to create, format and copy the charts in Excel, another in Word to paste the charts and create and format the textboxes. It'll be a bit complicated (for my capabilities) writing a macro in one application to run actions in another, but I've done it before. I'll give it a try and let you know how I get on.

    thank you for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Locking Column Width and Row Height
    By Zaraf in forum Excel General
    Replies: 7
    Last Post: 12-02-2013, 10:08 AM
  2. row height & col width in inches
    By hxly2 in forum Excel General
    Replies: 6
    Last Post: 02-17-2011, 08:37 AM
  3. Height macro request ...
    By rocket1406 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2007, 08:46 AM
  4. charting using height AND width
    By heski in forum Excel General
    Replies: 2
    Last Post: 10-12-2006, 08:53 PM
  5. Graphing height AND width
    By heski in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 10-04-2006, 07:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1